package scripting;

import client.*;
import client.inventory.*;
import cn.hutool.core.util.ObjectUtil;
import configs.Game;
import constants.GameConstants;
import constants.PlayerStatusTypeConstants;
import database.BeePool;
import gui.Start;
import handling.channel.ChannelServer;
import handling.channel.MapleGuildRanking;
import handling.channel.MapleGuildRanking.JobRankingInfo;
import handling.channel.handler.InterServerHandler;
import handling.login.LoginInformationProvider;
import handling.world.MapleParty;
import handling.world.MaplePartyCharacter;
import handling.world.World;
import handling.world.World.*;
import handling.world.guild.MapleGuild;
import lombok.extern.slf4j.Slf4j;
import repository.CharacterMaterialMapper;
import repository.impl.CharacterMaterialImpl;
import server.*;
import server.Timer.CloneTimer;
import server.Timer.EventTimer;
import server.gashapon.Gashapon;
import server.gashapon.GashaponFactory;
import server.life.*;
import server.maps.*;
import server.quest.MapleQuest;
import server.shops.HiredMerchant;
import tools.*;
import tools.packet.PlayerShopPacket;

import javax.script.Invocable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.Map.Entry;

@Slf4j
public class NPCConversationManager extends AbstractPlayerInteraction {
    private MapleClient c;
    private int npc;
    private int questid;
    private int mode;
    protected String script;
    private String getText;
    private byte type;
    private byte lastMsg;
    public boolean pendingDisposal;
    private Invocable iv;
    public Connection con;

    private CharacterMaterialMapper characterMaterialMapper;

    public NPCConversationManager(MapleClient c, int npc, int questid, int mode, String npcscript, byte type, Invocable iv) {
        super(c);
        this.lastMsg = -1;
        this.pendingDisposal = false;
        this.con = null;
        this.c = c;
        this.npc = npc;
        this.questid = questid;
        this.mode = mode;
        this.type = type;
        this.iv = iv;
        this.script = npcscript;
        this.characterMaterialMapper = new CharacterMaterialImpl();
    }

    public Invocable getIv() {
        return this.iv;
    }

    public int getMode() {
        return this.mode;
    }

    public int getNpc() {
        return this.npc;
    }

    public int getQuest() {
        return this.questid;
    }

    public String getScript() {
        return this.script;
    }

    public byte getType() {
        return this.type;
    }

    public void safeDispose() {
        this.pendingDisposal = true;
    }

    public void dispose() {
        NPCScriptManager.getInstance().dispose(this.c);
    }

    public void askMapSelection(String sel) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getMapSelection(this.npc, sel));
        this.lastMsg = 13;
    }

    public void sendNext(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 01", (byte) 0));
        this.lastMsg = 0;
    }

    public void sendNextS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimpleS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 01", type));
        this.lastMsg = 0;
    }

    public void sendPrev(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "01 00", (byte) 0));
        this.lastMsg = 0;
    }

    public void sendPrevS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimpleS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "01 00", type));
        this.lastMsg = 0;
    }

    public void sendNextPrev(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "01 01", (byte) 0));
        this.lastMsg = 0;
    }

    public void PlayerToNpc(String text) {
        this.sendNextPrevS(text, (byte) 3);
    }

    public void sendNextPrevS(String text) {
        this.sendNextPrevS(text, (byte) 3);
    }

    public void sendNextPrevS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimpleS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "01 01", type));
        this.lastMsg = 0;
    }

    public void sendOk(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 00", (byte) 0));
        this.lastMsg = 0;
    }

    public void sendOkS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimpleS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 00", type));
        this.lastMsg = 0;
    }

    public void sendOkS(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimpleS(text, this.type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 00", (byte) 2));
        this.lastMsg = 0;
    }

    public void sendYesNo(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 1, text, "", (byte) 0));
        this.lastMsg = 1;
    }

    public void sendYesNoS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimpleS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 1, text, "", type));
        this.lastMsg = 1;
    }

    public void sendYesNoS(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimpleS(text, this.type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 1, text, "", (byte) 2));
        this.lastMsg = 1;
    }

    public void sendAcceptDecline(String text) {
        this.askAcceptDecline(text);
    }

    public void sendAcceptDeclineNoESC(String text) {
        this.askAcceptDeclineNoESC(text);
    }

    public void askAcceptDecline(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 11, text, "", (byte) 0));
        this.lastMsg = 11;
    }

    public void askAcceptDeclineNoESC(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 12, text, "", (byte) 0));
        this.lastMsg = 12;
    }

    public void askAvatar(String text, int... args) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkStyle(this.npc, text, args));
        this.lastMsg = 7;
    }

    public void askAvatar(String text, int card, int... args) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.getSession().write(MaplePacketCreator.getNPCTalkStyle(this.npc, text, card, args));
        this.lastMsg = 7;
    }

    public void sendSimple(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (!text.contains("#L")) {
            this.sendNext(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 4, text, "", (byte) 0));
        this.lastMsg = 4;
    }

    public void sendSimple(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (!text.contains((CharSequence) "#L")) {
            this.sendNextS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 4, text, "", type));
        this.lastMsg = 4;
    }

    public void sendSimpleS(String text, byte type) {
        if (this.lastMsg > -1) {
            return;
        }
        if (!text.contains((CharSequence) "#L")) {
            this.sendNextS(text, type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 4, text, "", type));
        this.lastMsg = 4;
    }

    public void sendSimpleS(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (!text.contains((CharSequence) "#L")) {
            this.sendNextS(text, this.type);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalk(this.npc, (byte) 4, text, "", (byte) 2));
        this.lastMsg = 4;
    }

    public void sendStyle(String text, int[] styles) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkStyle(this.npc, text, styles));
        this.lastMsg = 7;
    }

    public void sendStyle(String text, int caid, int[] styles) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkStyle(this.id, text, caid, styles));
        this.lastMsg = 7;
    }

    public void sendSecondStyle(String text, int[] styles) {
        if (this.lastMsg > -1) {
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkStyle(this.id, text, styles));
        this.lastMsg = 7;
    }

    public void sendGetNumber(String text, int def, int min, int max) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains("#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkNum(this.npc, text, def, min, max));
        this.lastMsg = 3;
    }

    public void sendGetText(String text) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.sendPacket(MaplePacketCreator.getNPCTalkText(this.npc, text));
        this.lastMsg = 2;
    }

    public void setGetText(String text) {
        this.getText = text;
    }

    public String getText() {
        return this.getText;
    }

    public void setHair(int hair) {
        this.getPlayer().setHair(hair);
        this.getPlayer().updateSingleStat(MapleStat.HAIR, hair);
        this.getPlayer().equipChanged();
    }

    public void setFace(int face) {
        this.getPlayer().setFace(face);
        this.getPlayer().updateSingleStat(MapleStat.FACE, face);
        this.getPlayer().equipChanged();
    }

    public void setSkin(int color) {
        this.getPlayer().setSkinColor((byte) color);
        this.getPlayer().updateSingleStat(MapleStat.SKIN, color);
        this.getPlayer().equipChanged();
    }

    public int setRandomAvatar(int ticket, int... args_all) {
        if (!this.haveItem(ticket)) {
            return -1;
        }
        this.gainItem(ticket, (short) (-1));
        int args = args_all[Randomizer.nextInt(args_all.length)];
        if (args < 100) {
            this.c.getPlayer().setSkinColor((byte) args);
            this.c.getPlayer().updateSingleStat(MapleStat.SKIN, args);
        } else if (args < 30000) {
            this.c.getPlayer().setFace(args);
            this.c.getPlayer().updateSingleStat(MapleStat.FACE, args);
        } else {
            this.c.getPlayer().setHair(args);
            this.c.getPlayer().updateSingleStat(MapleStat.HAIR, args);
        }
        this.c.getPlayer().equipChanged();
        return 1;
    }

    public int setAvatar(int ticket, int args) {
        if (!this.haveItem(ticket)) {
            return -1;
        }
        this.gainItem(ticket, (short) (-1));
        if (args < 100) {
            this.c.getPlayer().setSkinColor((byte) args);
            this.c.getPlayer().updateSingleStat(MapleStat.SKIN, args);
        } else if (args < 30000) {
            this.c.getPlayer().setFace(args);
            this.c.getPlayer().updateSingleStat(MapleStat.FACE, args);
        } else {
            this.c.getPlayer().setHair(args);
            this.c.getPlayer().updateSingleStat(MapleStat.HAIR, args);
        }
        this.c.getPlayer().equipChanged();
        return 1;
    }

    public int setAvatars(int args) {
        if (args < 100) {
            this.c.getPlayer().setSkinColor((byte) args);
            this.c.getPlayer().updateSingleStat(MapleStat.SKIN, args);
        } else if (args < 30000) {
            this.c.getPlayer().setFace(args);
            this.c.getPlayer().updateSingleStat(MapleStat.FACE, args);
        } else {
            this.c.getPlayer().setHair(args);
            this.c.getPlayer().updateSingleStat(MapleStat.HAIR, args);
        }
        this.c.getPlayer().equipChanged();
        return 1;
    }

    public void sendStorage() {
        if (this.getPlayer().hasBlockedInventory2(true)) {
            this.c.getPlayer().dropMessage(1, "系统错误，请联系管理员。");
            this.c.sendPacket(MaplePacketCreator.enableActions());
            return;
        }
        if (!World.isShutDown) {
            if (!World.isShopShutDown) {
                this.c.getPlayer().setConversation(4);
                this.c.getPlayer().getStorage().sendStorage(this.c, this.npc);
            } else {
                this.c.getPlayer().dropMessage(1, "目前不能使用仓库。");
                this.c.sendPacket(MaplePacketCreator.enableActions());
            }
        } else {
            this.c.getPlayer().dropMessage(1, "目前不能使用仓库。");
            this.c.sendPacket(MaplePacketCreator.enableActions());
        }
    }

    public void openShop(int id) {
        MapleShopFactory.getInstance().getShop(id).sendShop(this.c);
    }

    public int gainGachaponItem(int id, int quantity, String msg, byte 概率) {
        try {
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                this.getPlayer().dropMessage(5, "gainGachaponItem itemExists(id) == -1");
                return -1;
            }
            IItem item = MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (item == null) {
                this.getPlayer().dropMessage(5, "gainGachaponItem item == -1");
                return -1;
            }
            if (概率 > 0) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "]", " : 被玩家 " + this.c.getPlayer().getName() + " 获得！大家一起来恭喜他吧！", item, 概率));
            }
            return item.getItemId();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    public int gainGachaponItem(int id, int quantity) {
        return this.gainGachaponItem(id, quantity, this.c.getPlayer().getMap().getStreetName() + " - " + this.c.getPlayer().getMap().getMapName());
    }

    public int gainGachaponItem(int id, int quantity, String msg) {
        try {
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                return -1;
            }
            IItem item = MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (item == null) {
                return -1;
            }
            byte rareness = (byte) (int) Math.floor((double) (item.getItemId() / 1000000));
            if (rareness == 1) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "]", " : 被玩家 " + this.c.getPlayer().getName() + " 获得！大家一起来恭喜他吧！", item, rareness));
            } else if (rareness == 2) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "]", " : 被玩家 " + this.c.getPlayer().getName() + " 获得！大家一起来恭喜他吧！", item, rareness));
            } else if (rareness > 2) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "]", " : 被玩家 " + this.c.getPlayer().getName() + " 获得！大家一起来恭喜他吧！", item, rareness));
            }
            return item.getItemId();
        } catch (Exception ex) {
            return -1;
        }
    }

    public int gainGachaponItem2(int id, int quantity) {
        return this.gainGachaponItem2(id, quantity, this.c.getPlayer().getMap().getStreetName());
    }

    public int gainGachaponItem2(int id, int quantity, String msg) {
        try {
            id = RandomRewards.getGoldBoxReward();
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                return -1;
            }
            Item item = (Item) MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (item == null) {
                return -1;
            }
            byte rareness = GameConstants.gachaponRareItem(item.getItemId());
            if (rareness > 0) {
                Broadcast.broadcastSmega(MaplePacketCreator.itemMegaphone("高级快乐百宝箱 : " + this.c.getPlayer().getName() + "获得该物品,大家恭喜他(她)吧!", true, this.c.getChannel(), (IItem) item));
            }
            this.c.getSession().write(MaplePacketCreator.getShowItemGain(item.getItemId(), (short) quantity, true));
            return item.getItemId();
        } catch (Exception ex) {
            return -1;
        }
    }

    public int gainGachaponItemTime(int id, int quantity, long period) {
        return this.gainGachaponItemTime(id, quantity, this.c.getPlayer().getMap().getStreetName() + " - " + this.c.getPlayer().getMap().getMapName(), period);
    }

    public int gainGachaponItemTime(int id, int quantity, String msg, long period) {
        try {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            if (!ii.itemExists(id)) {
                return -1;
            }
            IItem item = ii.isCash(id) ? MapleInventoryManipulator.addbyId_GachaponTime(this.c, id, (short) quantity, period) : MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (item == null) {
                return -1;
            }
            byte rareness = GameConstants.gachaponRareItem(item.getItemId());
            if (rareness == 1) {
                if (this.c.getPlayer().getMapId() == 910000000) {
                    Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[自由市场]", " : 恭喜玩家 " + this.c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                } else {
                    Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[隐藏地图-转蛋屋]", " : 恭喜玩家 " + this.c.getPlayer().getName() + " 在" + msg + "获得！", item, rareness));
                }
            } else if (rareness == 2) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 被他成功转到了，大家恭喜他吧！", item, rareness));
            } else if (rareness > 2) {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 被他从枫叶转蛋机转到了，大家恭喜他吧！", item, rareness));
            }
            return item.getItemId();
        } catch (Exception ex) {
            return -1;
        }
    }

    public void changeJob(int job) {
        this.c.getPlayer().changeJob(job);
    }

    public void startQuest(int id) {
        MapleQuest.getInstance(id).start(this.getPlayer(), this.npc);
    }

    @Override
    public void completeQuest(int id) {
        MapleQuest.getInstance(id).complete(this.getPlayer(), this.npc);
    }

    public void forfeitQuest(int id) {
        MapleQuest.getInstance(id).forfeit(this.getPlayer());
    }

    public void forceStartQuest() {
        MapleQuest.getInstance(this.questid).forceStart(this.getPlayer(), this.getNpc(), null);
    }

    @Override
    public void forceStartQuest(int id) {
        MapleQuest.getInstance(id).forceStart(this.getPlayer(), this.getNpc(), null);
    }

    public void forceStartQuest(String customData) {
        MapleQuest.getInstance(this.questid).forceStart(this.getPlayer(), this.getNpc(), customData);
    }

    public void completeQuest() {
        MapleQuest.getInstance(this.questid).forceComplete(this.getPlayer(), this.getNpc());
    }

    public void forceCompleteQuest() {
        MapleQuest.getInstance(this.questid).forceComplete(this.getPlayer(), this.getNpc());
    }

    @Override
    public void forceCompleteQuest(int id) {
        MapleQuest.getInstance(id).forceComplete(this.getPlayer(), this.getNpc());
    }

    public String getQuestCustomData() {
        return this.c.getPlayer().getQuestNAdd(MapleQuest.getInstance(this.questid)).getCustomData();
    }

    public void setQuestCustomData(String customData) {
        this.getPlayer().getQuestNAdd(MapleQuest.getInstance(this.questid)).setCustomData(customData);
    }

    public int getMeso() {
        return this.getPlayer().getMeso();
    }

    public void gainAp(int amount) {
        this.c.getPlayer().gainAp((short) amount);
    }

    public void expandInventory(byte type, int amt) {
        this.c.getPlayer().expandInventory(type, amt);
    }

    public void unequipEverything() {
        MapleInventory equipped = this.getPlayer().getInventory(MapleInventoryType.EQUIPPED);
        MapleInventory equip = this.getPlayer().getInventory(MapleInventoryType.EQUIP);
        List<Short> ids = (List<Short>) new LinkedList();
        for (IItem item : equipped.list()) {
            ids.add(Short.valueOf(item.getPosition()));
        }
        Iterator<Short> iterator2 = ids.iterator();
        while (iterator2.hasNext()) {
            short id = ((Short) iterator2.next()).shortValue();
            MapleInventoryManipulator.unequip(this.getC(), id, equip.getNextFreeSlot());
        }
    }

    public void clearSkills() {
        Map<ISkill, SkillEntry> skills = this.getPlayer().getSkills();
        for (Entry<ISkill, SkillEntry> skill : skills.entrySet()) {
            this.getPlayer().changeSkillLevel((ISkill) skill.getKey(), (byte) 0, (byte) 0);
        }
    }

    public String getSkillMenu(int skillMaster) {
        StringBuilder sb = new StringBuilder();
        Map<ISkill, SkillEntry> skills = this.getPlayer().getSkills();
        for (Entry<ISkill, SkillEntry> skilla : skills.entrySet()) {
            ISkill skill = SkillFactory.getSkill(((ISkill) skilla.getKey()).getId());
            int key = ((ISkill) skilla.getKey()).getId();
            if (skill.getMaxLevel() > 10 && ((SkillEntry) skilla.getValue()).masterlevel < skill.getMaxLevel()) {
                if (skillMaster > 20) {
                    if (((SkillEntry) skilla.getValue()).masterlevel >= 30 || ((SkillEntry) skilla.getValue()).masterlevel < 20 || skill.getMaxLevel() <= 20) {
                        continue;
                    }
                    sb.append("\r\n#L").append(((ISkill) skilla.getKey()).getId()).append("##s").append(key).append("##q").append(key).append("##l");
                } else {
                    if (((SkillEntry) skilla.getValue()).masterlevel >= 20) {
                        continue;
                    }
                    sb.append("\r\n#L").append(key).append("##s").append(key).append("##q").append(key).append("##l");
                }
            }
        }
        return sb.toString();
    }

    public boolean canUseSkillBook(int skillId, int masterLevel) {
        if (masterLevel > 0) {
            ISkill skill = SkillFactory.getSkill(skillId);
            if (this.getPlayer().getSkillLevel(skill) >= skill.getMaxLevel()) {
                return false;
            }
            int skillLevel = this.getPlayer().getSkillLevel(skill);
            if ((skillLevel >= 5 && masterLevel == 20) || (skillLevel >= 15 && masterLevel == 30)) {
                return true;
            }
        }
        return false;
    }

    public void useSkillBook(int skillId, int masterLevel) {
        ISkill skill = SkillFactory.getSkill(skillId);
        masterLevel = ((masterLevel > skill.getMaxLevel()) ? skill.getMaxLevel() : masterLevel);
        this.getPlayer().changeSkillLevel(skill, this.getPlayer().getSkillLevel(skill), (byte) masterLevel);
        this.getPlayer().getMap().broadcastMessage(MaplePacketCreator.useSkillBook(this.getPlayer(), 0, 0, true, true));
        this.enableActions();
    }

    public void useFailed() {
        this.getMap().broadcastMessage(MaplePacketCreator.useSkillBook(this.getPlayer(), 0, 0, true, false));
        this.enableActions();
    }

    public boolean hasSkill(int skillid) {
        ISkill theSkill = SkillFactory.getSkill(skillid);
        return theSkill != null && this.c.getPlayer().getSkillLevel(theSkill) > 0;
    }

    public boolean hasSkill(int skillId, int level) {
        ISkill theSkill = SkillFactory.getSkill(skillId);
        return theSkill != null && this.c.getPlayer().getSkillLevel(theSkill) >= level;
    }

    public void showEffect(boolean broadcast, String effect) {
        if (broadcast) {
            this.c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.showEffect(effect));
        } else {
            this.c.sendPacket(MaplePacketCreator.showEffect(effect));
        }
    }

    public void playSound(boolean broadcast, String sound) {
        if (broadcast) {
            this.c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.playSound(sound));
        } else {
            this.c.sendPacket(MaplePacketCreator.playSound(sound));
        }
    }

    public void environmentChange(boolean broadcast, String env) {
        if (broadcast) {
            this.c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.environmentChange(env, 2));
        } else {
            this.c.sendPacket(MaplePacketCreator.environmentChange(env, 2));
        }
    }

    public void updateBuddyCapacity(int capacity) {
        this.c.getPlayer().setBuddyCapacity((byte) capacity);
    }

    public int getBuddyCapacity() {
        return this.c.getPlayer().getBuddyCapacity();
    }

    public int partyMembersInMap() {
        int inMap = 0;
        for (MapleCharacter char2 : this.getPlayer().getMap().getCharactersThreadsafe()) {
            if (char2.getParty() == this.getPlayer().getParty()) {
                ++inMap;
            }
        }
        return inMap;
    }

    public List<MapleCharacter> getPartyMembers() {
        if (this.getPlayer().getParty() == null) {
            return null;
        }
        List<MapleCharacter> chars = (List<MapleCharacter>) new LinkedList();
        for (MaplePartyCharacter chr : this.getPlayer().getParty().getMembers()) {
            for (ChannelServer channel : ChannelServer.getAllInstances()) {
                MapleCharacter ch = channel.getPlayerStorage().getCharacterById(chr.getId());
                if (ch != null) {
                    chars.add(ch);
                }
            }
        }
        return chars;
    }

    public void warpPartyWithExp(int mapId, int exp) {
        MapleMap target = this.getMap(mapId);
        for (MaplePartyCharacter chr : this.getPlayer().getParty().getMembers()) {
            MapleCharacter curChar = this.c.getChannelServer().getPlayerStorage().getCharacterByName(chr.getName());
            if ((curChar.getEventInstance() == null && this.getPlayer().getEventInstance() == null) || curChar.getEventInstance() == this.getPlayer().getEventInstance()) {
                curChar.changeMap(target, target.getPortal(0));
                curChar.gainExp(exp, true, false, true);
            }
        }
    }

    public void warpPartyWithExpMeso(int mapId, int exp, int meso) {
        MapleMap target = this.getMap(mapId);
        for (MaplePartyCharacter chr : this.getPlayer().getParty().getMembers()) {
            MapleCharacter curChar = this.c.getChannelServer().getPlayerStorage().getCharacterByName(chr.getName());
            if ((curChar.getEventInstance() == null && this.getPlayer().getEventInstance() == null) || curChar.getEventInstance() == this.getPlayer().getEventInstance()) {
                curChar.changeMap(target, target.getPortal(0));
                curChar.gainExp(exp, true, false, true);
                curChar.gainMeso(meso, true);
            }
        }
    }

    public MapleSquad getSquad(String type) {
        return this.c.getChannelServer().getMapleSquad(type);
    }

    public int getSquadAvailability(String type) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        }
        return squad.getStatus();
    }

    public boolean registerSquad(String type, int minutes, String startText) {
        if (this.c.getChannelServer().getMapleSquad(type) == null) {
            MapleSquad squad = new MapleSquad(this.c.getChannel(), type, this.c.getPlayer(), minutes * 60 * 1000, startText);
            boolean ret = this.c.getChannelServer().addMapleSquad(squad, type);
            if (ret) {
                MapleMap map = this.c.getPlayer().getMap();
                map.broadcastMessage(MaplePacketCreator.getClock(minutes * 60));
                map.broadcastMessage(MaplePacketCreator.serverNotice(6, this.c.getPlayer().getName() + startText));
            } else {
                squad.clear();
            }
            return ret;
        }
        return false;
    }

    public boolean getSquadList(String type, byte type_) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return false;
        }
        if (type_ == 0 || type_ == 3) {
            this.sendNext(squad.getSquadMemberString(type_));
        } else if (type_ == 1) {
            this.sendSimple(squad.getSquadMemberString(type_));
        } else if (type_ == 2) {
            if (squad.getBannedMemberSize() > 0) {
                this.sendSimple(squad.getSquadMemberString(type_));
            } else {
                this.sendNext(squad.getSquadMemberString(type_));
            }
        }
        return true;
    }

    public byte isSquadLeader(String type) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        }
        if (squad.getLeader() != null && squad.getLeader().getId() == this.c.getPlayer().getId()) {
            return 1;
        }
        return 0;
    }

    public boolean reAdd(String eim, String squad) {
        EventInstanceManager eimz = this.getDisconnected(eim);
        MapleSquad squadz = this.getSquad(squad);
        if (eimz != null && squadz != null) {
            squadz.reAddMember(this.getPlayer());
            eimz.registerPlayer(this.getPlayer());
            return true;
        }
        return false;
    }

    public void banMember(String type, int pos) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            squad.banMember(pos);
        }
    }

    public void acceptMember(String type, int pos) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            squad.acceptMember(pos);
        }
    }

    public String getReadableMillis(long startMillis, long endMillis) {
        return StringUtil.getReadableMillis(startMillis, endMillis);
    }

    public int addMember(String type, boolean join) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad != null) {
            return squad.addMember(this.c.getPlayer(), join);
        }
        return -1;
    }

    public byte isSquadMember(String type) {
        MapleSquad squad = this.c.getChannelServer().getMapleSquad(type);
        if (squad == null) {
            return -1;
        }
        if (squad.getMembers().contains(this.c.getPlayer().getName())) {
            return 1;
        }
        if (squad.isBanned(this.c.getPlayer())) {
            return 2;
        }
        return 0;
    }

    public void resetReactors() {
        this.getPlayer().getMap().resetReactors();
    }

    public void genericGuildMessage(int code) {
        this.c.sendPacket(MaplePacketCreator.genericGuildMessage((byte) code));
    }

    public void disbandGuild() {
        int gid = this.c.getPlayer().getGuildId();
        if (gid <= 0 || this.c.getPlayer().getGuildRank() != 1) {
            return;
        }
        Guild.disbandGuild(gid);
    }

    public void increaseGuildCapacity() {
        if (this.c.getPlayer().getMeso() < 250000) {
            this.c.sendPacket(MaplePacketCreator.serverNotice(1, "你没有足够的金币."));
            return;
        }
        int gid = this.c.getPlayer().getGuildId();
        if (gid <= 0) {
            return;
        }
        Guild.increaseGuildCapacity(gid);
        this.c.getPlayer().gainMeso(-250000, true, false, true);
    }

    public void displayGuildRanks() {
        MapleGuild.displayGuildRanks(this.getClient(), this.npc);
    }

    public void showlvl() {
        MapleGuild.displayLevelRanks(this.getClient(), this.npc);
    }

    public void showmeso() {
        MapleGuild.meso(this.getClient(), this.npc);
    }

    public void showfame() {
        MapleGuild.fame(this.getClient(), this.npc);
    }

    public void ShowMarrageEffect() {
        this.c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.sendMarrageEffect());
    }

    public boolean removePlayerFromInstance() {
        if (this.c.getPlayer().getEventInstance() != null) {
            this.c.getPlayer().getEventInstance().removePlayer(this.c.getPlayer());
            return true;
        }
        return false;
    }

    public boolean isPlayerInstance() {
        return this.c.getPlayer().getEventInstance() != null;
    }

    public void changeStat(byte slot, int type, short amount) {
        Equip sel = (Equip) this.c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) slot);
        switch (type) {
            case 0: {
                sel.setStr(amount);
                break;
            }
            case 1: {
                sel.setDex(amount);
                break;
            }
            case 2: {
                sel.setInt(amount);
                break;
            }
            case 3: {
                sel.setLuk(amount);
                break;
            }
            case 4: {
                sel.setHp(amount);
                break;
            }
            case 5: {
                sel.setMp(amount);
                break;
            }
            case 6: {
                sel.setWatk(amount);
                break;
            }
            case 7: {
                sel.setMatk(amount);
                break;
            }
            case 8: {
                sel.setWdef(amount);
                break;
            }
            case 9: {
                sel.setMdef(amount);
                break;
            }
            case 10: {
                sel.setAcc(amount);
                break;
            }
            case 11: {
                sel.setAvoid(amount);
                break;
            }
            case 12: {
                sel.setHands(amount);
                break;
            }
            case 13: {
                sel.setSpeed(amount);
                break;
            }
            case 14: {
                sel.setJump(amount);
                break;
            }
            case 15: {
                sel.setUpgradeSlots((byte) amount);
                break;
            }
            case 16: {
                sel.setViciousHammer((byte) amount);
                break;
            }
            case 17: {
                sel.setLevel((byte) amount);
                break;
            }
            case 18: {
                sel.setEnhance((byte) amount);
                break;
            }
            case 19: {
                sel.setPotential1(amount);
                break;
            }
            case 20: {
                sel.setPotential2(amount);
                break;
            }
            case 21: {
                sel.setPotential3(amount);
                break;
            }
            case 22: {
                sel.setOwner(this.getText());
                break;
            }
        }
        this.c.getPlayer().equipChanged();
    }

    public void cleardrops() {
        MapleMonsterInformationProvider.getInstance().clearDrops();
    }

    public void killAllMonsters() {
        MapleMap map = this.c.getPlayer().getMap();
        double range = Double.POSITIVE_INFINITY;
        for (MapleMapObject monstermo : map.getMapObjectsInRange(this.c.getPlayer().getPosition(), range, Arrays.asList(MapleMapObjectType.MONSTER))) {
            MapleMonster mob = (MapleMonster) monstermo;
            if (mob.getStats().isBoss()) {
                map.killMonster(mob, this.c.getPlayer(), false, false, (byte) 1);
            }
        }
    }

    public void giveMerchantMesos() {
        long mesos = 0L;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT mesos FROM hiredmerchants WHERE merchantid = ?");
            ps.setInt(1, this.getPlayer().getId());
            ResultSet rs = ps.executeQuery();
            if (!rs.next()) {
                rs.close();
                ps.close();
            } else {
                mesos = rs.getLong("mesos");
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("UPDATE hiredmerchants SET mesos = 0 WHERE merchantid = ?");
            ps.setInt(1, this.getPlayer().getId());
            ps.executeUpdate();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("Error gaining mesos in hired merchant" + ex);
            FileoutputUtil.outError("logs/资料库异常.txt", (Throwable) ex);
        }
        this.c.getPlayer().gainMeso((int) mesos, true);
    }

    public void dc() {
        MapleCharacter victim = this.getChannelServer().getPlayerStorage().getCharacterByName(this.getPlayer().getName());
        victim.getClient().getSession().close();
        victim.getClient().disconnect(true, false);
    }

    public long getMerchantMesos() {
        long mesos = 0L;
        try (Connection con = BeePool.getConnection();
             PreparedStatement ps = con.prepareStatement("SELECT mesos FROM hiredmerchants WHERE merchantid = ?")) {
            ps.setInt(1, this.getPlayer().getId());
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    mesos = rs.getLong("mesos");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("Error gaining mesos in hired merchant" + ex);
            FileoutputUtil.outError("logs/资料库异常.txt", (Throwable) ex);
        }
        return mesos;
    }

    public void openDuey() {
        this.c.getPlayer().setConversation(2);
        this.c.sendPacket(MaplePacketCreator.sendDuey((byte) 9, null));
    }

    public void openMerchantItemStore() {
        if (!World.isShutDown) {
            this.c.getPlayer().setConversation(3);
            this.c.sendPacket(PlayerShopPacket.merchItemStore((byte) 34));
        } else {
            this.c.getPlayer().dropMessage(1, "目前不能使用精灵商人领取。");
            this.c.sendPacket(MaplePacketCreator.enableActions());
        }
    }

    public void sendRepairWindow() {
        this.c.sendPacket(MaplePacketCreator.sendRepairWindow(this.npc));
    }

    public int getDojoPoints() {
        return this.c.getPlayer().getDojo();
    }

    public void setDojoPoints(int point) {
        this.c.getPlayer().setDojo(this.c.getPlayer().getDojo() + point);
    }

    public int getDojoRecord() {
        return this.c.getPlayer().getDojoRecord();
    }

    public void setDojoRecord(boolean reset) {
        this.c.getPlayer().setDojoRecord(reset);
    }

    public boolean start_DojoAgent(boolean dojo, boolean party) {
        if (dojo) {
            return Event_DojoAgent.warpStartDojo(this.c.getPlayer(), party);
        }
        return Event_DojoAgent.warpStartAgent(this.c.getPlayer(), party);
    }

    public boolean start_PyramidSubway(int pyramid) {
        if (pyramid >= 0) {
            return Event_PyramidSubway.warpStartPyramid(this.c.getPlayer(), pyramid);
        }
        return Event_PyramidSubway.warpStartSubway(this.c.getPlayer());
    }

    public boolean bonus_PyramidSubway(int pyramid) {
        if (pyramid >= 0) {
            return Event_PyramidSubway.warpBonusPyramid(this.c.getPlayer(), pyramid);
        }
        return Event_PyramidSubway.warpBonusSubway(this.c.getPlayer());
    }

    public short getKegs() {
        return AramiaFireWorks.getInstance().getKegsPercentage();
    }

    public void giveKegs(int kegs) {
        AramiaFireWorks.getInstance().giveKegs(this.c.getPlayer(), kegs);
    }

    public short getSunshines() {
        return AramiaFireWorks.getInstance().getSunsPercentage();
    }

    public void addSunshines(int kegs) {
        AramiaFireWorks.getInstance().giveSuns(this.c.getPlayer(), kegs);
    }

    public short getDecorations() {
        return AramiaFireWorks.getInstance().getDecsPercentage();
    }

    public void addDecorations(int kegs) {
        try {
            AramiaFireWorks.getInstance().giveDecs(this.c.getPlayer(), kegs);
        } catch (Exception ex) {
        }
    }

    public MapleInventory getInventory(int type) {
        return this.c.getPlayer().getInventory(MapleInventoryType.getByType((byte) type));
    }

    public MapleCarnivalParty getCarnivalParty() {
        return this.c.getPlayer().getCarnivalParty();
    }

    public MapleCarnivalChallenge getNextCarnivalRequest() {
        return this.c.getPlayer().getNextCarnivalRequest();
    }

    public MapleCarnivalChallenge getCarnivalChallenge(MapleCharacter chr) {
        return new MapleCarnivalChallenge(chr);
    }

    public void maxStats() {
        Map<MapleStat, Integer> statup = new EnumMap(MapleStat.class);
        this.c.getPlayer().getStat().setStr((short) 32767);
        this.c.getPlayer().getStat().setDex((short) 32767);
        this.c.getPlayer().getStat().setInt((short) 32767);
        this.c.getPlayer().getStat().setLuk((short) 32767);
        this.c.getPlayer().getStat().setMaxHp((short) 30000);
        this.c.getPlayer().getStat().setMaxMp((short) 30000);
        this.c.getPlayer().getStat().setHp(30000);
        this.c.getPlayer().getStat().setMp(30000);
        statup.put(MapleStat.STR, Integer.valueOf(32767));
        statup.put(MapleStat.DEX, Integer.valueOf(32767));
        statup.put(MapleStat.LUK, Integer.valueOf(32767));
        statup.put(MapleStat.INT, Integer.valueOf(32767));
        statup.put(MapleStat.HP, Integer.valueOf(30000));
        statup.put(MapleStat.MAXHP, Integer.valueOf(30000));
        statup.put(MapleStat.MP, Integer.valueOf(30000));
        statup.put(MapleStat.MAXMP, Integer.valueOf(30000));
        this.c.sendPacket(MaplePacketCreator.updatePlayerStats(statup, this.c.getPlayer()));
    }

    public Pair<String, Map<Integer, String>> getSpeedRun(String typ) {
        SpeedRunType stype = SpeedRunType.valueOf(typ);
        if (SpeedRunner.getInstance().getSpeedRunData(stype) != null) {
            return SpeedRunner.getInstance().getSpeedRunData(stype);
        }
        return new Pair("", (Map<Integer, String>) new HashMap());
    }

    public boolean getSR(Pair<String, Map<Integer, String>> ma, int sel) {
        if ((ma.getRight()).get(Integer.valueOf(sel)) == null || ((String) (ma.getRight()).get(Integer.valueOf(sel))).length() <= 0) {
            this.dispose();
            return false;
        }
        this.sendOk((String) (ma.getRight()).get(Integer.valueOf(sel)));
        return true;
    }

    public Equip getEquip(int itemid) {
        return (Equip) MapleItemInformationProvider.getInstance().getEquipById(itemid);
    }

    public void setExpiration(Object statsSel, long expire) {
        if (statsSel instanceof Equip) {
            ((Equip) statsSel).setExpiration(System.currentTimeMillis() + expire * 24L * 60L * 60L * 1000L);
        }
    }

    public void setLock(Object statsSel) {
        if (statsSel instanceof Equip) {
            Equip eq = (Equip) statsSel;
            if (eq.getExpiration() == -1L) {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.LOCK.getValue()));
            } else {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.UNTRADEABLE.getValue()));
            }
        }
    }

    public boolean addFromDrop(Object statsSel) {
        if (statsSel instanceof IItem) {
            IItem it = (IItem) statsSel;
            return MapleInventoryManipulator.checkSpace(this.getClient(), it.getItemId(), (int) it.getQuantity(), it.getOwner()) && MapleInventoryManipulator.addFromDrop(this.getClient(), it, false);
        }
        return false;
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int offset, String type) {
        return this.replaceItem(slot, invType, statsSel, offset, type, false);
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int offset, String type, boolean takeSlot) {
        MapleInventoryType inv = MapleInventoryType.getByType((byte) invType);
        if (inv == null) {
            return false;
        }
        IItem item = this.getPlayer().getInventory(inv).getItem((short) (byte) slot);
        if (item == null || statsSel instanceof IItem) {
            item = (IItem) statsSel;
        }
        if (offset > 0) {
            if (inv != MapleInventoryType.EQUIP) {
                return false;
            }
            Equip eq = (Equip) item;
            if (takeSlot) {
                if (eq.getUpgradeSlots() < 1) {
                    return false;
                }
                eq.setUpgradeSlots((byte) (eq.getUpgradeSlots() - 1));
            }
            if (type.equalsIgnoreCase("Slots")) {
                eq.setUpgradeSlots((byte) (eq.getUpgradeSlots() + offset));
            } else if (type.equalsIgnoreCase("Level")) {
                eq.setLevel((byte) (eq.getLevel() + offset));
            } else if (type.equalsIgnoreCase("Hammer")) {
                eq.setViciousHammer((byte) (eq.getViciousHammer() + offset));
            } else if (type.equalsIgnoreCase("STR")) {
                eq.setStr((short) (eq.getStr() + offset));
            } else if (type.equalsIgnoreCase("DEX")) {
                eq.setDex((short) (eq.getDex() + offset));
            } else if (type.equalsIgnoreCase("INT")) {
                eq.setInt((short) (eq.getInt() + offset));
            } else if (type.equalsIgnoreCase("LUK")) {
                eq.setLuk((short) (eq.getLuk() + offset));
            } else if (type.equalsIgnoreCase("HP")) {
                eq.setHp((short) (eq.getHp() + offset));
            } else if (type.equalsIgnoreCase("MP")) {
                eq.setMp((short) (eq.getMp() + offset));
            } else if (type.equalsIgnoreCase("WATK")) {
                eq.setWatk((short) (eq.getWatk() + offset));
            } else if (type.equalsIgnoreCase("MATK")) {
                eq.setMatk((short) (eq.getMatk() + offset));
            } else if (type.equalsIgnoreCase("WDEF")) {
                eq.setWdef((short) (eq.getWdef() + offset));
            } else if (type.equalsIgnoreCase("MDEF")) {
                eq.setMdef((short) (eq.getMdef() + offset));
            } else if (type.equalsIgnoreCase("ACC")) {
                eq.setAcc((short) (eq.getAcc() + offset));
            } else if (type.equalsIgnoreCase("Avoid")) {
                eq.setAvoid((short) (eq.getAvoid() + offset));
            } else if (type.equalsIgnoreCase("Hands")) {
                eq.setHands((short) (eq.getHands() + offset));
            } else if (type.equalsIgnoreCase("Speed")) {
                eq.setSpeed((short) (eq.getSpeed() + offset));
            } else if (type.equalsIgnoreCase("Jump")) {
                eq.setJump((short) (eq.getJump() + offset));
            } else if (type.equalsIgnoreCase("ItemEXP")) {
                eq.setItemEXP(eq.getItemEXP() + offset);
            } else if (type.equalsIgnoreCase("Expiration")) {
                eq.setExpiration(eq.getExpiration() + (long) offset);
            } else if (type.equalsIgnoreCase("Flag")) {
                eq.setFlag((byte) (eq.getFlag() + offset));
            }
            if (eq.getExpiration() == -1L) {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.LOCK.getValue()));
            } else {
                eq.setFlag((byte) (eq.getFlag() | ItemFlag.UNTRADEABLE.getValue()));
            }
            item = eq.copy();
        }
        MapleInventoryManipulator.removeFromSlot(this.getClient(), inv, (short) slot, item.getQuantity(), false);
        return MapleInventoryManipulator.addFromDrop(this.getClient(), item, false);
    }

    public boolean replaceItem(int slot, int invType, Object statsSel, int upgradeSlots) {
        return this.replaceItem(slot, invType, statsSel, upgradeSlots, "Slots");
    }

    @Override
    public boolean isCash(int itemId) {
        return MapleItemInformationProvider.getInstance().isCash(itemId);
    }

    public boolean isOnlyTradeBlock(int itemId) {
        return MapleItemInformationProvider.getInstance().isOnlyTradeBlock(itemId);
    }

    public void buffGuild(int buff, int duration, String msg) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        if (ii.getItemEffect(buff) != null && this.getPlayer().getGuildId() > 0) {
            MapleStatEffect mse = ii.getItemEffect(buff);
            for (ChannelServer cserv : ChannelServer.getAllInstances()) {
                for (MapleCharacter chr : cserv.getPlayerStorage().getAllCharactersThreadSafe()) {
                    if (chr.getGuildId() == this.getPlayer().getGuildId()) {
                        mse.applyTo(chr, chr, true, null, duration);
                        chr.dropMessage(5, "Your guild has gotten a " + msg + " buff.");
                    }
                }
            }
        }
    }

    public boolean createAlliance(String alliancename) {
        MapleParty pt = this.c.getPlayer().getParty();
        MapleCharacter otherChar = this.c.getChannelServer().getPlayerStorage().getCharacterById(pt.getMemberByIndex(1).getId());
        if (otherChar == null || otherChar.getId() == this.c.getPlayer().getId()) {
            return false;
        }
        try {
            return Alliance.createAlliance(alliancename, this.c.getPlayer().getId(), otherChar.getId(), this.c.getPlayer().getGuildId(), otherChar.getGuildId());
        } catch (Exception re) {
            return false;
        }
    }

    public boolean addCapacityToAlliance() {
        try {
            MapleGuild gs = Guild.getGuild(this.c.getPlayer().getGuildId());
            if (gs != null && this.c.getPlayer().getGuildRank() == 1 && this.c.getPlayer().getAllianceRank() == 1 && Alliance.getAllianceLeader(gs.getAllianceId()) == this.c.getPlayer().getId() && Alliance.changeAllianceCapacity(gs.getAllianceId())) {
                this.gainMeso(-10000000);
                return true;
            }
        } catch (Exception ex) {
        }
        return false;
    }

    public boolean disbandAlliance() {
        try {
            MapleGuild gs = Guild.getGuild(this.c.getPlayer().getGuildId());
            if (gs != null && this.c.getPlayer().getGuildRank() == 1 && this.c.getPlayer().getAllianceRank() == 1 && Alliance.getAllianceLeader(gs.getAllianceId()) == this.c.getPlayer().getId() && Alliance.disbandAlliance(gs.getAllianceId())) {
                return true;
            }
        } catch (Exception ex) {
        }
        return false;
    }

    public byte getLastMsg() {
        return this.lastMsg;
    }

    public void setLastMsg(byte last) {
        this.lastMsg = last;
    }

    public void setPartyBossLog(String bossid) {
        MapleParty party = this.getPlayer().getParty();
        for (MaplePartyCharacter pc : party.getMembers()) {
            MapleCharacter chr = World.getStorage(this.getChannelNumber()).getCharacterById(pc.getId());
            if (chr != null) {
                chr.setBossLog(bossid);
            }
        }
    }

    public void maxAllSkills() {
        for (ISkill skil : SkillFactory.getAllSkills()) {
            if (GameConstants.isApplicableSkill(skil.getId())) {
                this.teachSkill(skil.getId(), skil.getMaxLevel(), skil.getMaxLevel());
            }
        }
    }

    public void resetStats(int str, int dex, int z, int luk) {
        this.c.getPlayer().resetStats(str, dex, z, luk);
    }

    public boolean dropItem(int slot, int invType, int quantity) {
        MapleInventoryType inv = MapleInventoryType.getByType((byte) invType);
        return inv != null && MapleInventoryManipulator.drop(this.c, inv, (short) slot, (short) quantity, true);
    }

    public List<Integer> getAllPotentialInfo() {
        return new ArrayList(MapleItemInformationProvider.getInstance().getAllPotentialInfo().keySet());
    }

    public String getPotentialInfo(int id) {
        List<StructPotentialItem> potInfo = MapleItemInformationProvider.getInstance().getPotentialInfo(id);
        StringBuilder builder = new StringBuilder("#b#ePOTENTIAL INFO FOR ID: ");
        builder.append(id);
        builder.append("#n#k\r\n\r\n");
        int minLevel = 1;
        int maxLevel = 10;
        for (StructPotentialItem item : potInfo) {
            builder.append("#eLevels ");
            builder.append(minLevel);
            builder.append("~");
            builder.append(maxLevel);
            builder.append(": #n");
            builder.append(item.toString());
            minLevel += 10;
            maxLevel += 10;
            builder.append("\r\n");
        }
        return builder.toString();
    }

    public void sendRPS() {
        this.c.sendPacket(MaplePacketCreator.getRPSMode((byte) 8, -1, -1, -1));
    }

    public void setQuestRecord(Object ch, int questid, String data) {
        ((MapleCharacter) ch).getQuestNAdd(MapleQuest.getInstance(questid)).setCustomData(data);
    }

    public void doWeddingEffect(Object ch) {
        MapleCharacter chr = (MapleCharacter) ch;
        this.getMap().broadcastMessage(MaplePacketCreator.yellowChat(chr.getName() + ", 你愿意承认 " + this.getPlayer().getName() + " 做你的丈夫，诚实遵照上帝的誡命，和他生活在一起，无论在什么环境愿顺服他、爱惜他、安慰他、尊重他保护他，以致奉召归主？？"));
        CloneTimer.getInstance().schedule((Runnable) new Runnable() {
            @Override
            public void run() {
                if (chr == null || NPCConversationManager.this.getPlayer() == null) {
                    NPCConversationManager.this.warpMap(680000500, 0);
                } else {
                    NPCConversationManager.this.getMap().broadcastMessage(MaplePacketCreator.yellowChat(NPCConversationManager.this.getPlayer().getName() + ", 你愿意承认接纳 " + chr.getName() + " 做你的妻子，诚实遵照上帝的誡命，和她生活在一起，无论在什么环境，愿意终生養她、爱惜她、安慰她、尊重她、保护她，以至奉召归主？？"));
                }
            }
        }, 10000L);
        CloneTimer.getInstance().schedule((Runnable) new Runnable() {
            @Override
            public void run() {
                if (chr == null || NPCConversationManager.this.getPlayer() == null) {
                    if (NPCConversationManager.this.getPlayer() != null) {
                        NPCConversationManager.this.setQuestRecord(NPCConversationManager.this.getPlayer(), 160001, "3");
                        NPCConversationManager.this.setQuestRecord(NPCConversationManager.this.getPlayer(), 160002, "0");
                    } else if (chr != null) {
                        NPCConversationManager.this.setQuestRecord(chr, 160001, "3");
                        NPCConversationManager.this.setQuestRecord(chr, 160002, "0");
                    }
                    NPCConversationManager.this.warpMap(680000500, 0);
                } else {
                    NPCConversationManager.this.setQuestRecord(NPCConversationManager.this.getPlayer(), 160001, "2");
                    NPCConversationManager.this.setQuestRecord(chr, 160001, "2");
                    NPCConversationManager.this.sendNPCText(NPCConversationManager.this.getPlayer().getName() + " 和 " + chr.getName() + "， 我希望你们两个能在此时此刻永远爱著对方！", 9201002);
                    NPCConversationManager.this.getMap().startExtendedMapEffect("那么现在请新娘亲吻 " + NPCConversationManager.this.getPlayer().getName() + "！", 5120006);
                    if (chr.getGuildId() > 0) {
                        Guild.guildPacket(chr.getGuildId(), MaplePacketCreator.sendMarriage(false, chr.getName()));
                    }
                    if (chr.getFamilyId() > 0) {
                        Family.familyPacket(chr.getFamilyId(), MaplePacketCreator.sendMarriage(true, chr.getName()), chr.getId());
                    }
                    if (NPCConversationManager.this.getPlayer().getGuildId() > 0) {
                        Guild.guildPacket(NPCConversationManager.this.getPlayer().getGuildId(), MaplePacketCreator.sendMarriage(false, NPCConversationManager.this.getPlayer().getName()));
                    }
                    if (NPCConversationManager.this.getPlayer().getFamilyId() > 0) {
                        Family.familyPacket(NPCConversationManager.this.getPlayer().getFamilyId(), MaplePacketCreator.sendMarriage(true, chr.getName()), NPCConversationManager.this.getPlayer().getId());
                    }
                }
            }
        }, 20000L);
    }

    public void 开启小钢珠(int type) {
        this.c.sendPacket(MaplePacketCreator.openBeans(this.getPlayer().getBeans(), type));
    }

    public void worldMessage(String text) {
        Broadcast.broadcastMessage(MaplePacketCreator.serverNotice(6, text));
    }

    public int getBeans() {
        return this.getClient().getPlayer().getBeans();
    }

    public void warpBackWithParty(int mid, int retmap, int time) {
        MapleMap warpMap = this.c.getChannelServer().getMapFactory().getMap(mid);
        for (MaplePartyCharacter chr : this.getPlayer().getParty().getMembers()) {
            MapleCharacter curChar = this.c.getChannelServer().getPlayerStorage().getCharacterByName(chr.getName());
            if (curChar != null && ((curChar.getEventInstance() == null && this.getPlayer().getEventInstance() == null) || curChar.getEventInstance() == this.getPlayer().getEventInstance())) {
                curChar.changeMap(warpMap, warpMap.getPortal(0));
                curChar.getClient().sendPacket(MaplePacketCreator.getClock(time));
                curChar.set副本地图(mid);
                EventTimer.getInstance().schedule((Runnable) new Runnable() {
                    @Override
                    public void run() {
                        MapleMap warpMap = NPCConversationManager.this.c.getChannelServer().getMapFactory().getMap(retmap);
                        if (curChar.getMapId() == mid && curChar.getMapId() == curChar.get副本地图()) {
                            curChar.getClient().sendPacket(MaplePacketCreator.stopClock());
                            curChar.changeMap(warpMap, warpMap.getPortal(0));
                            curChar.dropMessage(6, "已经到达目的地了!");
                        }
                    }
                }, (long) (1000 * time));
            }
        }
    }

    public void warpBack(int mid, int retmap, int time) {
        MapleMap warpMap = this.c.getChannelServer().getMapFactory().getMap(mid);
        this.c.getPlayer().changeMap(warpMap, warpMap.getPortal(0));
        this.c.sendPacket(MaplePacketCreator.getClock(time));
        EventTimer.getInstance().schedule((Runnable) new Runnable() {
            @Override
            public void run() {
                MapleMap warpMap = NPCConversationManager.this.c.getChannelServer().getMapFactory().getMap(retmap);
                if (NPCConversationManager.this.c.getPlayer() != null) {
                    NPCConversationManager.this.c.sendPacket(MaplePacketCreator.stopClock());
                    NPCConversationManager.this.c.getPlayer().changeMap(warpMap, warpMap.getPortal(0));
                    NPCConversationManager.this.c.getPlayer().dropMessage(6, "已经到达目的地了!");
                }
            }
        }, (long) (1000 * time));
    }

    public void ChangeName(String name) {
        this.getPlayer().setName(name);
        this.save();
        this.getPlayer().fakeRelog();
    }

    public String searchData(int type, String search) {
        return SearchGenerator.searchData(type, search);
    }

    public int[] getSearchData(int type, String search) {
        Map<Integer, String> data = SearchGenerator.getSearchData(type, search);
        if (data.isEmpty()) {
            return null;
        }
        int[] searches = new int[data.size()];
        int i = 0;
        Iterator<Integer> iterator = data.keySet().iterator();
        while (iterator.hasNext()) {
            int key = ((Integer) iterator.next()).intValue();
            searches[i] = key;
            ++i;
        }
        return searches;
    }

    public boolean foundData(int type, String search) {
        return SearchGenerator.foundData(type, search);
    }

    public boolean ReceiveMedal() {
        int acid = this.getPlayer().getAccountID();
        int id = this.getPlayer().getId();
        String name = this.getPlayer().getName();
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        int item = 1142475;
        if (!this.getPlayer().canHold(item)) {
            return false;
        }
        if (this.getPlayer().haveItem(item)) {
            return false;
        }
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT id FROM RCmedals WHERE name = ?");
            ps.setString(1, name);
            ResultSet rs = ps.executeQuery();
            if (!rs.first()) {
                return false;
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("Update RCmedals set amount = ? Where id = ?");
            ps.setInt(1, 0);
            ps.setInt(2, id);
            ps.execute();
            ps.close();
            
        } catch (Exception ex) {
            FilePrinter.printError("NPCConversationManager.txt", (Throwable) ex, "ReceiveMedal(" + name + ")");
            FileoutputUtil.outError("logs/资料库异常.txt", (Throwable) ex);
        }
        IItem toDrop = ii.randomizeStats((Equip) ii.getEquipById(item));
        toDrop.setGMLog(this.getPlayer().getName() + " 领取勋章");
        MapleInventoryManipulator.addbyItem(this.c, toDrop);
        FileoutputUtil.logToFile("logs/Data/NPC领取勋章.txt", "\r\n " + FileoutputUtil.NowTime() + " IP: " + this.c.getSession().remoteAddress().toString().split(":")[0] + " 账号: " + this.c.getAccountName() + " 玩家: " + this.c.getPlayer().getName() + " 领取了RC勋章");
        return true;
    }

    public String ShowJobRank(int type) {
        StringBuilder sb = new StringBuilder();
        List<JobRankingInfo> Ranking = MapleGuildRanking.getInstance().getJobRank(type);
        if (Ranking != null) {
            int num = 0;
            for (JobRankingInfo info : Ranking) {
                ++num;
                sb.append("#n#e#k排名:#r ");
                sb.append(num);
                sb.append("\r\n#n#e#k玩家名称:#d ");
                sb.append(StringUtil.getRightPaddedStr(info.getName(), ' ', 13));
                sb.append("\r\n#n#e#k等级:#e#r ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getLevel()), ' ', 3));
                sb.append("\r\n#n#e#k职业:#e#b ");
                sb.append(MapleJob.getName(MapleJob.getById(info.getJob())));
                sb.append("\r\n#n#e#k力量:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getStr()), ' ', 4));
                sb.append("\r\n#n#e#k敏捷:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getDex()), ' ', 4));
                sb.append("\r\n#n#e#k智力:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getInt()), ' ', 4));
                sb.append("\r\n#n#e#k幸运:#e#d ");
                sb.append(StringUtil.getRightPaddedStr(String.valueOf(info.getLuk()), ' ', 4));
                sb.append("\r\n");
                sb.append("#n#k======================================================\r\n");
            }
        } else {
            sb.append("#r查询无任何结果写");
        }
        return sb.toString();
    }

    public static boolean hairExists(int hair) {
        return MapleItemInformationProvider.hairList.containsKey(Integer.valueOf(hair));
    }

    public int[] getCanHair(int[] hairs) {
        List<Integer> canHair = (List<Integer>) new ArrayList();
        List<Integer> cantHair = (List<Integer>) new ArrayList();
        for (int hair : hairs) {
            if (hairExists(hair)) {
                canHair.add(Integer.valueOf(hair));
            } else {
                cantHair.add(Integer.valueOf(hair));
            }
        }
        if (cantHair.size() > 0 && this.c.getPlayer().isAdmin()) {
            StringBuilder sb = new StringBuilder("正在读取的发型裏有");
            sb.append(cantHair.size()).append("个发型客戶端不支持显示，已经被清除：");
            for (int i = 0; i < cantHair.size(); ++i) {
                sb.append(cantHair.get(i));
                if (i < cantHair.size() - 1) {
                    sb.append(",");
                }
            }
            this.playerMessage(sb.toString());
        }
        int[] getHair = new int[canHair.size()];
        for (int i = 0; i < canHair.size(); ++i) {
            getHair[i] = ((Integer) canHair.get(i)).intValue();
        }
        return getHair;
    }

    public static boolean faceExists(int face) {
        return MapleItemInformationProvider.faceLists.containsKey(Integer.valueOf(face));
    }

    public int[] getCanFace(int[] faces) {
        List<Integer> canFace = (List<Integer>) new ArrayList();
        List<Integer> cantFace = (List<Integer>) new ArrayList();
        for (int face : faces) {
            if (faceExists(face)) {
                canFace.add(Integer.valueOf(face));
            } else {
                cantFace.add(Integer.valueOf(face));
            }
        }
        if (cantFace.size() > 0 && this.c.getPlayer().isAdmin()) {
            StringBuilder sb = new StringBuilder("正在读取的脸型裏有");
            sb.append(cantFace.size()).append("个脸型客戶端不支持显示，已经被清除：");
            for (int i = 0; i < cantFace.size(); ++i) {
                sb.append(cantFace.get(i));
                if (i < cantFace.size() - 1) {
                    sb.append(",");
                }
            }
            this.playerMessage(sb.toString());
        }
        int[] getFace = new int[canFace.size()];
        for (int i = 0; i < canFace.size(); ++i) {
            getFace[i] = ((Integer) canFace.get(i)).intValue();
        }
        return getFace;
    }

    public String checkDrop(int mobId, boolean GM) {
        List<MonsterDropEntry> ranks = MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId);
        if (ranks != null && ranks.size() > 0) {
            int num = 0;
            int itemId = 0;
            int ch = 0;
            int ab = 1;
            StringBuilder name = new StringBuilder();
            for (int i = 0; i < ranks.size(); ++i) {
                MonsterDropEntry de = (MonsterDropEntry) ranks.get(i);
                if (de.chance > 0 && (de.questid <= 0 || (de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0))) {
                    itemId = de.itemId;
                    if (num == 0) {
                        name.append("当前怪物 #o" + mobId + "# 的爆率为:\r\n");
                        name.append("当前系统爆率为:" + this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率 + "\r\n");
                        name.append("--------------------------------------\r\n");
                    }
                    String namez = "#z" + itemId + "#";
                    if (itemId == 0) {
                        itemId = 4031041;
                        if (((Integer) Start.ConfigValuesMap.get("金币全局砍数量")).intValue() > 0) {
                            ab = ((Integer) Start.ConfigValuesMap.get("金币砍全局倍率")).intValue();
                        }
                        namez = de.Minimum * this.getClient().getChannelServer().getMesoRate() * MapleParty.活动金币倍率 / ab + " 到 " + de.Maximum * this.getClient().getChannelServer().getMesoRate() * MapleParty.活动金币倍率 / ab + " 金币";
                    }
                    ch = de.chance * this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率;
                    if (GM) {
                        name.append(num + 1 + ") #v" + itemId + "#" + namez + " - " + Integer.valueOf((ch >= 999999) ? 1000000 : ch).doubleValue() / 10000.0 + "% 爆率。 " + ((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? ("需要接受任务 " + MapleQuest.getInstance((int) de.questid).getName() + "") : "") + "\r\n");
                    } else {
                        name.append(num + 1 + ") #v" + itemId + "#" + namez + " " + ((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? ("需要接受任务 " + MapleQuest.getInstance((int) de.questid).getName() + "") : "") + "\r\n");
                    }
                    ++num;
                }
            }
            if (name.length() > 0) {
                return name.toString();
            }
        }
        return "沒有当前怪物的爆率数据。";
    }

    public String checkDrop(MapleCharacter chr, int mobId, boolean GM) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        List<MonsterDropEntry> ranks = MapleMonsterInformationProvider.getInstance().retrieveDrop(mobId);
        if (ranks != null && ranks.size() > 0) {
            int num = 0;
            int itemId = 0;
            int ch = 0;
            int ab = 1;
            StringBuilder name = new StringBuilder();
            StringBuilder error = new StringBuilder();
            name.append("【#r#o" + mobId + "##k】掉宝物品查询列表:#b\r\n");
            for (int i = 0; i < ranks.size(); ++i) {
                MonsterDropEntry de = (MonsterDropEntry) ranks.get(i);
                if (de.chance > 0 && (de.questid <= 0 || (de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0))) {
                    itemId = de.itemId;
                    String namez = "#z" + itemId + "#";
                    if (itemId == 0) {
                        itemId = 4031041;
                        if (((Integer) Start.ConfigValuesMap.get("金币全局砍数量")).intValue() > 0) {
                            ab = ((Integer) Start.ConfigValuesMap.get("金币砍全局倍率")).intValue();
                        }
                        namez = de.Minimum * this.getClient().getChannelServer().getMesoRate() / ab + " to " + de.Maximum * this.getClient().getChannelServer().getMesoRate() / ab + " #b金币#l#k";
                    } else if (itemId != 0 && ii.itemExists(itemId)) {
                        ch = de.chance * this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率;
                        if (!GM) {
                            name.append("#k" + (num + 1) + ": #v" + itemId + "# " + namez + (chr.isGM() ? ("#d  掉落机率：" + Integer.valueOf((ch >= 999999) ? 1000000 : ch).doubleValue() / 10000.0 + "%\r\n") : "\r\n") + "#b(掉落条件:" + ((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? ("需要接取任务#r " + MapleQuest.getInstance((int) de.questid).getName() + " #b)\r\n") : "#r无#b)") + "\r\n");
                        } else {
                            name.append("#L" + itemId + "##k" + (num + 1) + ": #v" + itemId + "# " + namez + (chr.isGM() ? ("#d  掉落机率：" + Integer.valueOf((ch >= 999999) ? 1000000 : ch).doubleValue() / 10000.0 + "%(点選更改)\r\n") : "\r\n") + "#b(掉落条件:" + ((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? ("需要接取任务#r " + MapleQuest.getInstance((int) de.questid).getName() + " #b)\r\n") : "#r无#b)") + "\r\n");
                        }
                        ++num;
                    } else {
                        error.append(itemId + "\r\n");
                    }
                }
            }
            if (GM) {
                name.append("\r\n#L10000##k" + (num + 1) + ": #b我要额外新增掉落物品!");
            }
            if (error.length() > 0) {
                chr.dropMessage(1, "无效的物品ID:\r\n" + error.toString());
            }
            if (name.length() > 0) {
                return name.toString();
            }
        }
        return "该怪物查无任何掉宝数据。";
    }

    public String checkMapDrop() {
        List ranks = new ArrayList((Collection) MapleMonsterInformationProvider.getInstance().getGlobalDrop());
        int mapid = this.c.getPlayer().getMap().getId();
        int globalServerRate = 1;
        if (ranks != null && ranks.size() > 0) {
            int num = 0;
            StringBuilder name = new StringBuilder();
            for (int i = 0; i < ranks.size(); ++i) {
                MonsterGlobalDropEntry de = (MonsterGlobalDropEntry) ranks.get(i);
                int itemId = de.itemId;
                String names = "#z" + itemId + "#";
                int chance = de.chance * this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率;
                if (this.getPlayer().isAdmin()) {
                    name.append("#b#v").append(itemId).append("#").append(names).append("#k 爆率: ").append(Integer.valueOf((chance >= 999999) ? 1000000 : chance).doubleValue() / 10000.0).append(" %").append((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? ("需要接受任务: " + MapleQuest.getInstance((int) de.questid).getName()) : "").append("#k\r\n");
                } else {
                    name.append("#b#v").append(itemId).append("#").append(names).append((de.questid > 0 && MapleQuest.getInstance((int) de.questid).getName().length() > 0) ? (" #d需要接受任务: #r" + MapleQuest.getInstance((int) de.questid).getName()) : "").append("#k\r\n");
                }
                ++num;
            }
            if (name.length() > 0) {
                return name.toString();
            }
        }
        return "全局爆物数据为空。";
    }

    public void gainBeans(int s) {
        this.getPlayer().gainBeans(s);
        this.c.getSession().write(MaplePacketCreator.updateBeans(this.c.getPlayer()));
    }

    public void openBeans() {
        this.c.getSession().write(MaplePacketCreator.openBeans(this.getPlayer().getBeans(), 0));
        this.c.getPlayer().dropMessage(5, "按住左右鍵可以调整力道,建议调好角度一路给他打,不要按暂停若九宮格卡住沒反应请离开在近来");
    }

    public void setMonsterRiding(int itemid) {
        short src = this.getClient().getPlayer().haveItemPos(itemid);
        if (src == 100) {
            this.c.getPlayer().dropMessage(5, "你沒有当前坐骑。");
        } else {
            MapleInventoryManipulator.equip(this.c, src, (short) (-18));
            this.c.getPlayer().dropMessage(5, "装备坐骑成功。");
        }
    }

    public int getRandom(int... args_all) {
        int args = args_all[Randomizer.nextInt(args_all.length)];
        return args;
    }

    public void OwlAdv(int point, int itemid) {
        owlse(this.c, point, itemid);
    }

    public static void owlse(MapleClient c, int point, int itemid) {
        int itemSearch = itemid;
        List<HiredMerchant> hms = (List<HiredMerchant>) new ArrayList();
        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
            if (!cserv.searchMerchant(itemSearch).isEmpty()) {
                hms.addAll(cserv.searchMerchant(itemSearch));
            }
        }
        if (hms.size() > 0) {
            if (c.getPlayer().haveItem(5230000, 1)) {
                MapleInventoryManipulator.removeById(c, MapleInventoryType.CASH, 5230000, 1, true, false);
            } else if (c.getPlayer().getCSPoints(point) >= 5) {
                c.getPlayer().modifyCSPoints(point, -5, true);
            } else {
                c.getPlayer().dropMessage(1, "点数不足，无法查询！");
                if (NPCScriptManager.getInstance().getCM(c) != null) {
                    NPCScriptManager.getInstance().dispose(c);
                    c.sendPacket(MaplePacketCreator.enableActions());
                }
            }
            if (NPCScriptManager.getInstance().getCM(c) != null) {
                NPCScriptManager.getInstance().dispose(c);
            }
            c.sendPacket(MaplePacketCreator.getOwlSearched(itemSearch, hms));
        } else {
            if (NPCScriptManager.getInstance().getCM(c) != null) {
                NPCScriptManager.getInstance().dispose(c);
                c.sendPacket(MaplePacketCreator.enableActions());
            }
            c.getPlayer().dropMessage(1, "找不到物品");
        }
    }

    public void checkMobs(MapleCharacter chr) {
        if (this.getMap().getAllMonstersThreadsafe().size() <= 0) {
            this.sendOk("#地图上沒有怪物哦!!。");
            this.dispose();
        }
        String msg = "玩家 #b" + chr.getName() + "#k 此地图怪物掉宝查询:\r\n#r(若有任何掉宝問题,请至社团BUG区回报怪物名称和代码)\r\n#d";
        for (Object monsterid : this.getMap().getAllUniqueMonsters()) {
            msg = msg + "#L" + monsterid + "##o" + monsterid + "# 代码:" + monsterid + " (查看)#l\r\n";
        }
        this.sendOk(msg);
    }

    public void getMobs(int itemid) {
        MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
        List<Integer> mobs = MapleMonsterInformationProvider.getInstance().getMobByItem(itemid);
        String text = "#d这些怪物会掉落您查询的物品#k: \r\n\r\n";
        for (int i = 0; i < mobs.size(); ++i) {
            int quest = 0;
            if (mi.getDropQuest(((Integer) mobs.get(i)).intValue()) > 0) {
                quest = mi.getDropQuest(((Integer) mobs.get(i)).intValue());
            }
            int chance = mi.getDropChance(((Integer) mobs.get(i)).intValue()) * this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率;
            text = text + "#r#o" + mobs.get(i) + "##k " + ((quest > 0 && MapleQuest.getInstance(quest).getName().length() > 0) ? ("#b需要进行 " + MapleQuest.getInstance(quest).getName() + " 任务来取得#k") : "") + "\r\n";
        }
        this.sendNext(text);
    }

    public void getMob(int itemid) {
        MapleMonsterInformationProvider mi = MapleMonsterInformationProvider.getInstance();
        List<Integer> mobs = MapleMonsterInformationProvider.getInstance().getMobByItem(itemid);
        String text = "#d这些怪物会掉落您查询的物品#k: \r\n\r\n";
        int a = 0;
        for (int i = 0; i < mobs.size(); ++i) {
            int quest = 0;
            if (mi.getDropQuest(((Integer) mobs.get(i)).intValue()) > 0) {
                quest = mi.getDropQuest(((Integer) mobs.get(i)).intValue());
            }
            int chance = mi.getDropChance(((Integer) mobs.get(i)).intValue()) * this.getClient().getChannelServer().getDropRate() * MapleParty.活动爆率倍率;
            text = text + "#L" + mobs.get(i) + "##r#o" + mobs.get(i) + "##k " + ((quest > 0 && MapleQuest.getInstance(quest).getName().length() > 0) ? ("#b需要进行 " + MapleQuest.getInstance(quest).getName() + " 任务来取得#k") : "") + "\r\n";
            a = 1;
        }
        if (a == 1) {
            this.sendNext(text);
        } else {
            text += "不好意思啥都没找到\r\n";
            this.sendOk(text);
            this.dispose();
        }
    }

    public Gashapon getGashapon() {
        return GashaponFactory.getInstance().getGashaponByNpcId(this.getNpc());
    }

    public void getGachaponMega(String msg, Item item, int quantity) {
        Broadcast.broadcastGashponmega(MaplePacketCreator.getGachaponMega(this.c.getPlayer().getName(), " : x" + quantity + "恭喜玩家 " + this.c.getPlayer().getName() + " 在" + msg + "获得！", (IItem) item, (byte) 1, this.c.getPlayer().getClient().getChannel()));
    }

    public void EnterCS(int mod) {
        this.c.getPlayer().setCsMod(mod);
        InterServerHandler.EnterCashShop(this.c, this.c.getPlayer(), false);
    }

    public int[] getSavedFaces() {
        return this.getPlayer().getSavedFaces();
    }

    public int getSavedFace(int sel) {
        return this.getPlayer().getSavedFace(sel);
    }

    public void setSavedFace(int sel, int id) {
        this.getPlayer().setSavedFace(sel, id);
    }

    public int[] getSavedHairs() {
        return this.getPlayer().getSavedHairs();
    }

    public int getSavedHair(int sel) {
        return this.getPlayer().getSavedHair(sel);
    }

    public void setSavedHair(int sel, int id) {
        this.getPlayer().setSavedHair(sel, id);
    }

    public void changeJobById(short job) {
        this.c.getPlayer().changeJob((int) job);
    }

    public int getJobId() {
        return this.getPlayer().getJob();
    }

    public int getLevel() {
        return this.getPlayer().getLevel();
    }

    public int getEquipId(byte slot) {
        MapleInventory equip = this.getPlayer().getInventory(MapleInventoryType.EQUIP);
        Equip eu = (Equip) equip.getItem((short) slot);
        return equip.getItem((short) slot).getItemId();
    }

    public int getUseId(byte slot) {
        MapleInventory use = this.getPlayer().getInventory(MapleInventoryType.USE);
        return use.getItem((short) slot).getItemId();
    }

    public int getSetupId(byte slot) {
        MapleInventory setup = this.getPlayer().getInventory(MapleInventoryType.SETUP);
        return setup.getItem((short) slot).getItemId();
    }

    public int getCashId(byte slot) {
        MapleInventory cash = this.getPlayer().getInventory(MapleInventoryType.CASH);
        return cash.getItem((short) slot).getItemId();
    }

    public int getETCId(byte slot) {
        MapleInventory etc = this.getPlayer().getInventory(MapleInventoryType.ETC);
        return etc.getItem((short) slot).getItemId();
    }

    public String EquipList(MapleClient c) {
        StringBuilder str = new StringBuilder();
        MapleInventory equip = c.getPlayer().getInventory(MapleInventoryType.EQUIP);
        List<String> stra = (List<String>) new LinkedList();
        for (IItem item : equip.list()) {
            stra.add("#L" + (int) item.getPosition() + "##v" + item.getItemId() + "##l");
        }
        for (String strb : stra) {
            str.append(strb);
        }
        return str.toString();
    }

    public String UseList(MapleClient c) {
        StringBuilder str = new StringBuilder();
        MapleInventory use = c.getPlayer().getInventory(MapleInventoryType.USE);
        List<String> stra = (List<String>) new LinkedList();
        for (IItem item : use.list()) {
            stra.add("#L" + (int) item.getPosition() + "##v" + item.getItemId() + "##l");
        }
        for (String strb : stra) {
            str.append(strb);
        }
        return str.toString();
    }

    public String CashList(MapleClient c) {
        StringBuilder str = new StringBuilder();
        MapleInventory cash = c.getPlayer().getInventory(MapleInventoryType.CASH);
        List<String> stra = (List<String>) new LinkedList();
        for (IItem item : cash.list()) {
            stra.add("#L" + (int) item.getPosition() + "##v" + item.getItemId() + "##l");
        }
        for (String strb : stra) {
            str.append(strb);
        }
        return str.toString();
    }

    public String ETCList(MapleClient c) {
        StringBuilder str = new StringBuilder();
        MapleInventory etc = c.getPlayer().getInventory(MapleInventoryType.ETC);
        List<String> stra = (List<String>) new LinkedList();
        for (IItem item : etc.list()) {
            stra.add("#L" + (int) item.getPosition() + "##v" + item.getItemId() + "##l");
        }
        for (String strb : stra) {
            str.append(strb);
        }
        return str.toString();
    }

    public String SetupList(MapleClient c) {
        StringBuilder str = new StringBuilder();
        MapleInventory setup = c.getPlayer().getInventory(MapleInventoryType.SETUP);
        List<String> stra = (List<String>) new LinkedList();
        for (IItem item : setup.list()) {
            stra.add("#L" + (int) item.getPosition() + "##v" + item.getItemId() + "##l");
        }
        for (String strb : stra) {
            str.append(strb);
        }
        return str.toString();
    }

    public void sendNext(String text, int id) {
        if (this.lastMsg > -1) {
            return;
        }
        if (text.contains((CharSequence) "#L")) {
            this.sendSimple(text);
            return;
        }
        this.c.getSession().write(MaplePacketCreator.getNPCTalk(this.npc, (byte) 0, text, "00 01", (byte) 0));
        this.lastMsg = 0;
    }

    public static boolean itemExists(int itemId) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        for (Pair<Integer, String> item : ii.getAllItems2()) {
            if (((Integer) item.getLeft()).intValue() == itemId) {
                return true;
            }
        }
        return false;
    }

    public int gainGachaponItema(int id, int quantity, String msg) {
        try {
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                return -1;
            }
            IItem item = MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (item == null) {
                return -1;
            }
            byte rareness = 1;
            Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
            return item.getItemId();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    public int gainGachaponItem2(int id, int quantity, String msg, int 概率) {
        return this.gainGachaponItem2(id, quantity, msg, 概率, 0);
    }

    public int gainGachaponItem2(int id, int quantity, String msg, int 概率, int 类型) {
        try {
            if (!MapleItemInformationProvider.getInstance().itemExists(id)) {
                return -1;
            }
            IItem item = MapleInventoryManipulator.addbyId_Gachapon(this.c, id, (short) quantity);
            if (概率 > 0 && 类型 > 0) {
                switch (类型) {
                    case 1: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                    case 2: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                    case 3: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                    case 4: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                    case 5: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                    case 6: {
                        Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
                        break;
                    }
                }
            } else {
                Broadcast.broadcastMessage(MaplePacketCreator.getGachaponMega("[" + msg + "] " + this.c.getPlayer().getName(), " : 从抽奖中获得，大家恭喜他（她）吧！！！", item, (byte) 0, this.getPlayer().getClient().getChannel()));
            }
            return item.getItemId();
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }

    public int gainGachaponIte(int id, int quantity) {
        return this.gainGachaponItem(id, quantity, this.c.getPlayer().getMap().getStreetName());
    }

    public void changeJob(short job) {
        this.c.getPlayer().changeJob((int) job);
    }

    public String getQuestCustomData(int quest) {
        return this.c.getPlayer().getQuestNAdd(MapleQuest.getInstance(quest)).getCustomData();
    }

    public void makeTaintedEquip(byte slot) {
        Equip sel = (Equip) this.c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) slot);
        sel.setStr((short) 69);
        sel.setDex((short) 69);
        sel.setInt((short) 69);
        sel.setLuk((short) 69);
        sel.setHp((short) 69);
        sel.setMp((short) 69);
        sel.setWatk((short) 69);
        sel.setMatk((short) 69);
        sel.setWdef((short) 69);
        sel.setMdef((short) 69);
        sel.setAcc((short) 69);
        sel.setAvoid((short) 69);
        sel.setHands((short) 69);
        sel.setSpeed((short) 69);
        sel.setJump((short) 69);
        sel.setUpgradeSlots((byte) 69);
        sel.setViciousHammer((byte) 69);
        sel.setEnhance((byte) 69);
        this.c.getPlayer().equipChanged();
        this.c.getPlayer().fakeRelog();
    }

    public void changeStat(byte slot, int type, int amount) {
        Equip sel = (Equip) this.c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem((short) slot);
        switch (type) {
            case 0: {
                sel.setStr((short) amount);
                break;
            }
            case 1: {
                sel.setDex((short) amount);
                break;
            }
            case 2: {
                sel.setInt((short) amount);
                break;
            }
            case 3: {
                sel.setLuk((short) amount);
                break;
            }
            case 4: {
                sel.setHp((short) amount);
                break;
            }
            case 5: {
                sel.setMp((short) amount);
                break;
            }
            case 6: {
                sel.setWatk((short) amount);
                break;
            }
            case 7: {
                sel.setMatk((short) amount);
                break;
            }
            case 8: {
                sel.setWdef((short) amount);
                break;
            }
            case 9: {
                sel.setMdef((short) amount);
                break;
            }
            case 10: {
                sel.setAcc((short) amount);
                break;
            }
            case 11: {
                sel.setAvoid((short) amount);
                break;
            }
            case 12: {
                sel.setHands((short) amount);
                break;
            }
            case 13: {
                sel.setSpeed((short) amount);
                break;
            }
            case 14: {
                sel.setJump((short) amount);
                break;
            }
            case 15: {
                sel.setUpgradeSlots((byte) amount);
                break;
            }
            case 16: {
                sel.setViciousHammer((byte) amount);
                break;
            }
            case 17: {
                sel.setLevel((byte) amount);
                break;
            }
            case 18: {
                sel.setEnhance((byte) amount);
                break;
            }
            case 19: {
                sel.setPotential1((short) amount);
                break;
            }
            case 20: {
                sel.setPotential2((short) amount);
                break;
            }
            case 21: {
                sel.setPotential3((short) amount);
                break;
            }
            case 24: {
                sel.setOwner(this.getText());
                break;
            }
        }
        this.c.getPlayer().equipChanged();
        this.c.getPlayer().fakeRelog();
    }

    @Override
    public MapleCharacter getChar() {
        return this.getPlayer();
    }

    public static int editEquipById(MapleCharacter chr, int max, int itemid, String stat, int newval) {
        return editEquipById(chr, max, itemid, stat, (short) newval);
    }

    public static int editEquipById(MapleCharacter chr, int max, int itemid, String stat, short newval) {
        if (!MapleItemInformationProvider.getInstance().isEquip(itemid)) {
            return -1;
        }
        List<IItem> equips = chr.getInventory(MapleInventoryType.EQUIP).listById(itemid);
        List<IItem> equipped = chr.getInventory(MapleInventoryType.EQUIPPED).listById(itemid);
        if (equips.isEmpty() && equipped.isEmpty()) {
            return 0;
        }
        int edited = 0;
        for (IItem itm : equips) {
            Equip e = (Equip) itm;
            if (edited >= max) {
                break;
            }
            ++edited;
            String s = stat;
            switch (s) {
                case "str": {
                    e.setStr(newval);
                    continue;
                }
                case "dex": {
                    e.setDex(newval);
                    continue;
                }
                case "int": {
                    e.setInt(newval);
                    continue;
                }
                case "luk": {
                    e.setLuk(newval);
                    continue;
                }
                case "watk": {
                    e.setWatk(newval);
                    continue;
                }
                case "matk": {
                    e.setMatk(newval);
                    continue;
                }
                default: {
                    return -2;
                }
            }
        }
        for (IItem itm : equipped) {
            Equip e = (Equip) itm;
            if (edited >= max) {
                break;
            }
            ++edited;
            String s = stat;
            switch (s) {
                case "str": {
                    e.setStr(newval);
                    continue;
                }
                case "dex": {
                    e.setDex(newval);
                    continue;
                }
                case "int": {
                    e.setInt(newval);
                    continue;
                }
                case "luk": {
                    e.setLuk(newval);
                    continue;
                }
                case "watk": {
                    e.setWatk(newval);
                    continue;
                }
                case "matk": {
                    e.setMatk(newval);
                    continue;
                }
                default: {
                    return -2;
                }
            }
        }
        return edited;
    }

    public int getzb() {
        return this.c.getPlayer().getSYJF(this.c.getPlayer().getId());
    }

    public void gainzb(int slot) {
        this.c.getPlayer().setSYJF(this.c.getPlayer().getId(), slot);
    }

    public int getVPoints() {
        return this.getPlayer().getVPoints();
    }

    public void setVPoints(int vpoints) {
        this.getPlayer().setVPoints(this.getPlayer().getVPoints() + vpoints);
    }

    public int getDPoints() {
        return this.getPlayer().getVPoints();
    }

    public int getTotalStat(int itemId) {
        return MapleItemInformationProvider.getInstance().getTotalStat((Equip) MapleItemInformationProvider.getInstance().getEquipById(itemId));
    }

    public int getReqLevel(int itemId) {
        return MapleItemInformationProvider.getInstance().getReqLevel(itemId);
    }

    public MapleStatEffect getEffect(int buff) {
        return MapleItemInformationProvider.getInstance().getItemEffect(buff);
    }

    public void killAllMonsters(int mapid) {
        MapleMap map = this.c.getChannelServer().getMapFactory().getMap(mapid);
        map.killAllMonsters(false);
    }

    public void killAllMobs() {
        this.c.getPlayer().getMap().killAllMonsters(true);
    }

    public void levelUp() {
        this.c.getPlayer().levelUp();
    }

    public void MakeGMItem(byte slot, MapleCharacter player) {
        MapleInventory equip = player.getInventory(MapleInventoryType.EQUIP);
        Equip eu = (Equip) equip.getItem((short) slot);
        int item = equip.getItem((short) slot).getItemId();
        short hand = eu.getHands();
        byte level = eu.getLevel();
        Equip nItem = new Equip(item, (short) slot, (byte) 0);
        nItem.setStr((short) 32767);
        nItem.setDex((short) 32767);
        nItem.setInt((short) 32767);
        nItem.setLuk((short) 32767);
        nItem.setUpgradeSlots((byte) 0);
        nItem.setHands(hand);
        nItem.setLevel(level);
        player.getInventory(MapleInventoryType.EQUIP).removeItem((short) slot);
        player.getInventory(MapleInventoryType.EQUIP).addFromDB((IItem) nItem);
    }

    public void putKey(int key, int type, int action) {
        this.getPlayer().changeKeybinding(key, (byte) type, action);
        this.getClient().sendPacket(MaplePacketCreator.getKeymap(this.getPlayer().getKeyLayout()));
    }

    public int getNaturalStats(int itemid, String it) {
        Map<String, Integer> eqStats = MapleItemInformationProvider.getInstance().getEquipStats(itemid);
        if (eqStats != null && eqStats.containsKey(it)) {
            return ((Integer) eqStats.get(it)).intValue();
        }
        return 0;
    }

    public String getLeftPadded(String in, char padchar, int length) {
        return StringUtil.getLeftPaddedStr(in, padchar, length);
    }

    public void handleDivorce() {
        if (this.getPlayer().getMarriageId() <= 0) {
            this.sendNext("请确保你有一个婚姻.");
            return;
        }
        int chz = Find.findChannel(this.getPlayer().getMarriageId());
        if (chz == -1) {
            try (Connection con = BeePool.getConnection()) {
                PreparedStatement ps = con.prepareStatement("UPDATE queststatus SET customData = ? WHERE characterid = ? AND (quest = ? OR quest = ?)");
                ps.setString(1, "0");
                ps.setInt(2, this.getPlayer().getMarriageId());
                ps.setInt(3, 160001);
                ps.setInt(4, 160002);
                ps.executeUpdate();
                ps.close();
                ps = con.prepareStatement("UPDATE characters SET marriageid = ? WHERE id = ?");
                ps.setInt(1, 0);
                ps.setInt(2, this.getPlayer().getMarriageId());
                ps.executeUpdate();
                ps.close();
                
            } catch (SQLException e) {
                System.err.println("handleDivorce" + e);
                FileoutputUtil.outputFileError("logs/数据库异常.txt", (Throwable) e);
                return;
            }
            this.setQuestRecord(this.getPlayer(), 160001, "0");
            this.setQuestRecord(this.getPlayer(), 160002, "0");
            this.getPlayer().setMarriageId(0);
            this.sendNext("你已经成功离婚了..");
            return;
        }
        if (chz < -1) {
            this.sendNext("请确认您的伴侣已登录.");
            return;
        }
        MapleCharacter cPlayer = ChannelServer.getInstance(chz).getPlayerStorage().getCharacterById(this.getPlayer().getMarriageId());
        if (cPlayer != null) {
            cPlayer.dropMessage(1, "你的伴侣已经和你离婚了.");
            cPlayer.setMarriageId(0);
            this.setQuestRecord(cPlayer, 160001, "0");
            this.setQuestRecord(this.getPlayer(), 160001, "0");
            this.setQuestRecord(cPlayer, 160002, "0");
            this.setQuestRecord(this.getPlayer(), 160002, "0");
            this.getPlayer().setMarriageId(0);
            this.sendNext("你已经成功离婚了...");
        } else {
            this.sendNext("发生错误...");
        }
    }

    public void wearEquip(int itemid, byte slot) {
        MapleItemInformationProvider li = MapleItemInformationProvider.getInstance();
        MapleInventory equip = this.c.getPlayer().getInventory(MapleInventoryType.EQUIPPED);
        IItem item = li.getEquipById(itemid);
        item.setPosition((short) slot);
        equip.addFromDB(item);
    }

    public int parseInt(String s) {
        return Integer.parseInt(s);
    }

    public byte parseByte(String s) {
        return Byte.parseByte(s);
    }

    public short parseShort(String s) {
        return Short.parseShort(s);
    }

    public long parseLong(String s) {
        return Long.parseLong(s);
    }

    public void dragonShoutReward(int reward) {
        int itemid = 0;
        switch (reward) {
            case 0: {
                itemid = 1102207;
                break;
            }
            case 1: {
                itemid = 1122080;
                break;
            }
            case 2: {
                itemid = 2041213;
                break;
            }
            case 3: {
                itemid = 2022704;
                break;
            }
            default: {
                itemid = 2022704;
                break;
            }
        }
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        MapleInventoryType invtype = GameConstants.getInventoryType(itemid);
        if (!MapleInventoryManipulator.checkSpace(this.c, itemid, 1, "")) {
            return;
        }
        if (invtype.equals(MapleInventoryType.EQUIP) && !GameConstants.isThrowingStar(itemid) && !GameConstants.isBullet(itemid)) {
            Equip item = (Equip) (Equip) ii.getEquipById(itemid);
            switch (reward) {
                case 0: {
                    item.setPotential1((short) (-25485));
                    item.setPotential2((short) (-25484));
                    item.setPotential3((short) (-24935));
                    break;
                }
                case 1: {
                    item.setPotential1((short) (-25450));
                    item.setPotential2((short) (-25450));
                    item.setPotential3((short) (-25450));
                    break;
                }
            }
            item.setOwner("Hyperious");
            item.setGMLog("Received from interaction " + this.id + " (" + this.id2 + ") (The Dragon's Shout PQ) on " + FileoutputUtil.CurrentReadable_Time());
            String name = ii.getName(itemid);
            if (itemid / 10000 == 114 && name != null && name.length() > 0) {
                String msg = "< " + name + " > has been rewarded.";
                this.c.getPlayer().dropMessage(-1, msg);
                this.c.getPlayer().dropMessage(5, msg);
            }
            MapleInventoryManipulator.addbyItem(this.c, item.copy());
        } else {
            MapleInventoryManipulator.addById(this.c, itemid, (short) 1, "Hyperious", null, 0L, false, "Received from interaction " + this.id + " (" + this.id2 + ") on " + FileoutputUtil.CurrentReadable_Date());
        }
        this.c.sendPacket(MaplePacketCreator.getShowItemGain(itemid, (short) 1, true));
    }

    public boolean partyHaveItem(int itemid, short quantity) {
        if (this.getPlayer().getParty() == null) {
            return false;
        }
        for (MaplePartyCharacter chr : this.getPlayer().getParty().getMembers()) {
            for (ChannelServer channel : ChannelServer.getAllInstances()) {
                MapleCharacter ch = channel.getPlayerStorage().getCharacterById(chr.getId());
                if (ch != null && !ch.haveItem(itemid, (int) quantity)) {
                    return false;
                }
            }
        }
        return true;
    }

    public long currentTimeMillis() {
        return System.currentTimeMillis();
    }

    public MapleQuest getQuestById(int questId) {
        return MapleQuest.getInstance(questId);
    }

    public int getEquipLevelById(int itemId) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        return ((Integer) ii.getEquipStats(itemId).get("reqLevel")).intValue();
    }

    @Override
    public void 喇叭(int lx, String msg) {
        switch (lx) {
            case 1: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(12, this.c.getChannel(), "[全服公告] : " + msg));
                break;
            }
            case 2: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(2, "[全服公告] : " + msg));
                break;
            }
            case 3: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(3, this.c.getChannel(), "[全服公告] : " + msg, true));
                break;
            }
            case 4: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(9, this.c.getChannel(), "[全服公告] : " + msg, false));
                break;
            }
            case 5: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(11, this.c.getChannel(), "[全服公告] : " + msg));
                break;
            }
        }
    }

    @Override
    public void 喇叭(int lx, String msg1, String msg) {
        switch (lx) {
            case 1: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(12, this.c.getChannel(), "[" + msg1 + "] : " + msg));
                break;
            }
            case 2: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(2, "[" + msg1 + "] : " + msg));
                break;
            }
            case 3: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(3, this.c.getChannel(), "[" + msg1 + "] : " + msg, true));
                break;
            }
            case 4: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(9, this.c.getChannel(), "[" + msg1 + "] : " + msg, false));
                break;
            }
            case 5: {
                Broadcast.broadcastSmega(MaplePacketCreator.serverNotice(11, this.c.getChannel(), "[" + msg1 + "] : " + msg));
                break;
            }
        }
    }

    public void 家族排行榜() {
        this.displayGuildRanks();
    }

    public void 等级排行榜() {
        this.showlvl();
    }

    public void 金币排行榜() {
        this.showmeso();
    }

    public short getSpace(byte type) {
        return this.getPlayer().getSpace((int) type);
    }

    public void removeFromSlot(int type, short slot, short number) {
        this.getPlayer().removeFromSlot(type, slot, number);
    }

    public void addFromDrop(IItem item, boolean a) {
        this.getPlayer().addFromDrop(item, a);
    }

    public void gainEquiPproperty(int upgr, int watk, int matk, int str, int dex, int Int, int luk, int hp, int mp, int acc, int avoid) {
        Equip item = (Equip) this.c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((short) 1).copy();
        item.setUpgradeSlots((byte) (item.getUpgradeSlots() + upgr));
        item.setWatk((short) (item.getWatk() + watk));
        item.setMatk((short) (item.getMatk() + matk));
        item.setStr((short) (item.getStr() + str));
        item.setDex((short) (item.getDex() + dex));
        item.setInt((short) (item.getInt() + Int));
        item.setLuk((short) (item.getLuk() + luk));
        item.setHp((short) (item.getHp() + hp));
        item.setMp((short) (item.getMp() + mp));
        item.setAcc((short) (byte) (item.getAcc() + acc));
        item.setAvoid((short) (byte) (item.getAvoid() + avoid));
        MapleInventoryManipulator.removeFromSlot(this.getC(), MapleInventoryType.EQUIP, (short) 1, (short) 1, true);
        MapleInventoryManipulator.addFromDrop(this.getChar().getClient(), (IItem) item, false);
    }

    public void 刷新能力值() {
        if (this.c.getPlayer().getRemainingAp() < 0) {
            this.c.getPlayer().setRemainingAp((short) 0);
        }
    }

    public void 重载事件() {
        Iterator<ChannelServer> iterator = ChannelServer.getAllInstances().iterator();
        if (iterator.hasNext()) {
            ChannelServer instance = (ChannelServer) iterator.next();
            instance.reloadEvents();
            return;
        }
    }

    public void 重载任务() {
        MapleQuest.clearQuests();
    }

    public void 重载商店() {
        MapleShopFactory.getInstance().clear();
    }

    public void 重载传送点() {
        PortalScriptManager.getInstance().clearScripts();
    }

    public void 重载爆率() {
        MapleMonsterInformationProvider.getInstance().clearDrops();
    }

    public void 重载反应堆() {
        ReactorScriptManager.getInstance().clearDrops();
    }

    public int getHour() {
        return Calendar.getInstance().get(11);
    }

    public int getMin() {
        return Calendar.getInstance().get(12);
    }

    public int getSec() {
        return Calendar.getInstance().get(13);
    }

    public int 捉鬼任务1() {
        return MapleParty.捉鬼任务地图;
    }

    public int 捉鬼任务2() {
        return MapleParty.捉鬼任务频道;
    }

    public int 捉鬼任务3() {
        return MapleParty.捉鬼任务坐标X;
    }

    public int 捉鬼任务4() {
        return MapleParty.捉鬼任务坐标Y;
    }

    public void 即时存档() {
        this.c.getPlayer().saveToDB(true, true);
    }

    public boolean CheckMembersLevel(int lvl) {
        if (this.getParty() == null) {
            return false;
        }
        for (MaplePartyCharacter player : this.getParty().getMembers()) {
            if (player.getLevel() <= lvl) {
                continue;
            }
            if (!this.isLeader()) {
                return false;
            }
        }
        return true;
    }

    public int 查询在线人数() {
        int count = 0;
        for (ChannelServer chl : ChannelServer.getAllInstances()) {
            count += chl.getPlayerStorage().getAllCharacters().size();
        }
        return count;
    }

    public static int 获取最高玩家等级() {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT MAX(level) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取最高等级玩家名字() {
        String name = "";
        String level = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `level` FROM characters WHERE gm = 0 ORDER BY `level` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("level");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return String.format("%s", name);
    }

    public static String 获取家族名称(int guildId) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM guilds WHERE guildid = ?");
            ps.setInt(1, guildId);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static int 获取最高玩家人气() {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT MAX(fame) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
                rs.close();
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取最高人气玩家名字() {
        String name = "";
        String level = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `fame` FROM characters WHERE gm = 0 ORDER BY `fame` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("fame");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return String.format("%s", name);
    }

    public static int 获取最高玩家金币() {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT MAX(meso) as DATA FROM characters WHERE gm = 0");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取最高玩家等级出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public static String 获取最高金币玩家名字() {
        String name = "";
        String level = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT `name`, `meso` FROM characters WHERE gm = 0 ORDER BY `meso` DESC LIMIT 1");
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    name = rs.getString("name");
                    level = rs.getString("meso");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取家族名称出错 - 数据库查询失败：" + Ex);
        }
        return String.format("%s", name);
    }

    public int 获取自己等级排名() {
        int DATA = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT rank FROM (SELECT @rownum := @rownum + 1 AS rank, `name`, `level`, `id` FROM characters, (SELECT @rownum := 0) r WHERE gm = 0 ORDER BY `level` DESC) AS T1 WHERE `id` = ?");
            ps.setInt(1, this.c.getPlayer().getId());
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    DATA = rs.getInt("rank");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取自己等级排名出错 - 数据库查询失败：" + Ex);
        }
        return DATA;
    }

    @Override
    public String getItemName(int id) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        return ii.getName(id);
    }

    public void deleteItem(int inventorytype) {
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("Select * from inventoryitems where characterid=? and inventorytype=?");
            ps.setInt(1, this.getPlayer().getId());
            ps.setInt(2, inventorytype);
            ResultSet re = ps.executeQuery();
            MapleInventoryType type = null;
            switch (inventorytype) {
                case 1: {
                    type = MapleInventoryType.EQUIP;
                    break;
                }
                case 2: {
                    type = MapleInventoryType.USE;
                    break;
                }
                case 3: {
                    type = MapleInventoryType.SETUP;
                    break;
                }
                case 4: {
                    type = MapleInventoryType.ETC;
                    break;
                }
                case 5: {
                    type = MapleInventoryType.CASH;
                    break;
                }
            }
            while (re.next()) {
                MapleInventoryManipulator.removeById(this.getC(), type, re.getInt("itemid"), re.getInt("quantity"), true, true);
            }
            re.close();
            ps.close();
            
        } catch (SQLException ex) {
        }
    }

    public int 获取当前星期() {
        return Calendar.getInstance().get(7);
    }

    public int getsg() {
        int sg = 0;
        try (Connection con = BeePool.getConnection()) {
            int cid = this.getPlayer().getAccountID();
            PreparedStatement limitCheck = con.prepareStatement("SELECT * FROM characters WHERE id=" + cid + "");
            ResultSet rs = limitCheck.executeQuery();
            if (rs.next()) {
                sg = rs.getInt("sg");
            }
            rs.close();
            limitCheck.close();
        } catch (SQLException ex) {
        }
        return sg;
    }

    public void setsg(int slot) {
        try (Connection con = BeePool.getConnection()) {
            int cid = this.getPlayer().getAccountID();
            PreparedStatement ps = con.prepareStatement("UPDATE characters SET sg =sg+ " + slot + " WHERE id = " + cid + "");
            ps.executeUpdate();
            ps.close();
        } catch (SQLException ex) {
        }
    }

    public boolean checkLevelAndItem(int minLevel, int maxLevel, int itemId) {
        return this.checkLevelAndItem(minLevel, maxLevel, itemId, 2);
    }

    public boolean checkLevelAndItem(int minLevel, int maxLevel, int itemId, int minSize) {
        MapleParty party = this.getPlayer().getParty();
        if (party == null || party.getLeader().getId() != this.getPlayer().getId()) {
            this.getPlayer().dropMessage(5, "您没有队伍 或者 不是队长..");
            return false;
        }
        int partySize = party.getMembers().size();
        if (partySize < minSize) {
            this.getPlayer().dropMessage(5, "队伍的人数成员不够 必须 " + minSize + " 人才可以开始组队任务，当前队伍人数: " + partySize);
            return false;
        }
        int chrSize = 0;
        for (MaplePartyCharacter partyPlayer : party.getMembers()) {
            MapleCharacter player = this.getPlayer().getMap().getCharacterById(partyPlayer.getId());
            if (player == null) {
                this.getPlayer().dropMessage(5, "队伍中的成员 " + partyPlayer.getName() + " 不在线 或者 不在同一地图.");
            } else if (player.getLevel() < minLevel || player.getLevel() > maxLevel) {
                this.getPlayer().dropMessage(5, "队伍中的成员 " + partyPlayer.getName() + " 等级不符合要求.等级限制: Lv." + minLevel + "～" + maxLevel);
            } else if (!player.haveItem(itemId)) {
                this.getPlayer().dropMessage(5, "队伍中的成员 " + partyPlayer.getName() + " 没有开始组队任务需要的道具.");
            } else {
                ++chrSize;
            }
        }
        return partySize == chrSize;
    }

    public void deleteAll(int itemId) {
        MapleInventoryManipulator.removeAllById(this.getClient(), itemId, true);
    }

    public MapleCharacter getCharByName(String name) {
        try {
            return this.getClient().getChannelServer().getPlayerStorage().getCharacterByName(name);
        } catch (Exception e) {
            return null;
        }
    }

    public void SystemOutPrintln(String text) {
        if (this.c.getPlayer().isGM()) {
            this.c.getPlayer().dropMessage(1, "[Npc_Debug]" + text);
        }
        System.out.println(text);
    }

    public void UpdateDropChance(int chance, int dropperid, int itemid) {
        MapleMonsterInformationProvider.getInstance().UpdateDropChance(chance, dropperid, itemid);
    }

    public void AddDropData(int chance, int dropperid, int itemid, int questid) {
        MapleMonsterInformationProvider.getInstance().AddDropData(chance, dropperid, itemid, questid);
    }

    public void DeleteDropData(int dropperid, int itemid) {
        MapleMonsterInformationProvider.getInstance().DeleteDropData(dropperid, itemid);
    }

    public String 显示物品列表种类选择(int a) {
        StringBuilder name = new StringBuilder();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT DISTINCT itemid FROM auctionitems  WHERE inventorytype = " + a + " && world = " + (int) this.c.getPlayer().getWorld() + ";");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 物品 = rs.getInt("itemid");
                name.append("#L").append(物品).append("# #v").append(物品).append("# #b#z").append(物品).append("##k#l\r\n");
            }
            rs.close();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("显示物品列表种类选择、出错" + ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        name.append("\r\n");
        return name.toString();
    }

    public String 显示我上架的物品列表种类选择(int a) {
        StringBuilder name = new StringBuilder();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT DISTINCT itemid FROM  auctionitems  WHERE inventorytype = " + a + " && characterid = " + this.c.getPlayer().getId() + ";");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 物品 = rs.getInt("itemid");
                name.append("#L").append(物品).append("# #v").append(物品).append("# #b#t").append(物品).append("##k#l\r\n");
            }
            rs.close();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("显示物品列表种类选择、出错" + ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        name.append("\r\n");
        return name.toString();
    }

    public String 显示物品列表详细(int a) {
        StringBuilder name = new StringBuilder();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE itemid = " + a + " && world = " + (int) this.c.getPlayer().getWorld() + " order by price asc;");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 序号 = rs.getInt("id");
                int 物品 = rs.getInt("itemid");
                int 价格 = rs.getInt("price");
                int 数量 = rs.getInt("quantity");
                if (rs.getInt("inventorytype") == 1) {
                    name.append("#L").append(序号).append("# #v").append(物品).append("# #b#t").append(物品).append("##k 价格 : #r").append(价格).append("#k#l\r\n");
                } else {
                    name.append("#L").append(序号).append("# #v").append(物品).append("# #b#z").append(物品).append("##k 价格 : #r").append(价格).append("#k   数量 :  #b").append(数量).append("#k#l\r\n");
                }
            }
            rs.close();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("显示物品列表详细、出错" + ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        name.append("\r\n");
        return name.toString();
    }

    public String 显示我的物品列表详细(int a) {
        StringBuilder name = new StringBuilder();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE itemid = " + a + " && characterid = " + this.c.getPlayer().getId() + "  &&  world = " + (int) this.c.getPlayer().getWorld() + " order by price asc");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int 序号 = rs.getInt("id");
                int 物品 = rs.getInt("itemid");
                int 价格 = rs.getInt("price");
                int 数量 = rs.getInt("quantity");
                if (rs.getInt("inventorytype") == 1) {
                    name.append("#L").append(序号).append("# #v").append(物品).append("# #b#t").append(物品).append("##k 价格 : #r").append(价格).append("#k#l\r\n");
                } else {
                    name.append("#L" + 序号 + "# #v" + 物品 + "# #b#t" + 物品 + "##k 价格 : #r" + 价格 + "#k   数量 :  #b" + 数量 + "#k#l\r\n");
                }
            }
            rs.close();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("显示物品列表详细、出错" + ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        name.append("\r\n");
        return name.toString();
    }

    public String 显示物品数据详细(int a) {
        StringBuilder name = new StringBuilder();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE id = " + a + "");
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                int 物品 = rs.getInt("itemid");
                name.append("#b物品: #v").append(物品).append("# #b#t").append(物品).append("##k\r\n");
                int 卖家 = rs.getInt("characterid");
                name.append("#b卖家: #r").append(this.取角色名字(卖家)).append("#k\r\n");
                int 售价 = rs.getInt("price");
                name.append("#b售价: #r").append(售价).append("#k #b#k\r\n");
                int 数量 = rs.getInt("quantity");
                name.append("#b数量: #r").append(数量).append("#k\r\n");
                String 上架时间 = rs.getString("shijian");
                name.append("#b上架时间: #r").append(上架时间).append("#k\r\n");
                if (物品 < 2000000) {
                    int 攻击力 = rs.getInt("watk");
                    if (攻击力 > 0) {
                        name.append("#b攻击力 : #r").append(攻击力).append("#k\r\n");
                    }
                    int 魔法力 = rs.getInt("matk");
                    if (魔法力 > 0) {
                        name.append("#b魔法力 : #r").append(魔法力).append("#k\r\n");
                    }
                    int 物理防御 = rs.getInt("wdef");
                    if (物理防御 > 0) {
                        name.append("#b物理防御 : #r").append(物理防御).append("#k\r\n");
                    }
                    int 魔法防御 = rs.getInt("mdef");
                    if (魔法防御 > 0) {
                        name.append("#b魔法防御 : #r").append(魔法防御).append("#k\r\n");
                    }
                    int 力量 = rs.getInt("str");
                    if (力量 > 0) {
                        name.append("#b力量 : #r").append(力量).append("#k\r\n");
                    }
                    int 敏捷 = rs.getInt("dex");
                    if (敏捷 > 0) {
                        name.append("#b敏捷 : #r").append(敏捷).append("#k\r\n");
                    }
                    int 智力 = rs.getInt("_int");
                    if (智力 > 0) {
                        name.append("#b智力 : #r").append(智力).append("#k\r\n");
                    }
                    int 运气 = rs.getInt("luk");
                    if (运气 > 0) {
                        name.append("#b运气 : #r").append(运气).append("#k\r\n");
                    }
                    int 生命值 = rs.getInt("hp");
                    if (生命值 > 0) {
                        name.append("#b生命值 : #r").append(生命值).append("#k\r\n");
                    }
                    int 魔力值 = rs.getInt("mp");
                    if (魔力值 > 0) {
                        name.append("#b魔力值 : #r").append(魔力值).append("#k\r\n");
                    }
                    int 命中 = rs.getInt("acc");
                    if (命中 > 0) {
                        name.append("#b命中 : #r").append(命中).append("#k\r\n");
                    }
                    int 回避 = rs.getInt("avoid");
                    if (回避 > 0) {
                        name.append("#b回避 : #r").append(回避).append("#k\r\n");
                    }
                    int 手技 = rs.getInt("hands");
                    if (手技 > 0) {
                        name.append("#b手技 : #r").append(手技).append("#k\r\n");
                    }
                    int 移速 = rs.getInt("speed");
                    if (移速 > 0) {
                        name.append("#b移速 : #r").append(移速).append("#k\r\n");
                    }
                    int 跳跃 = rs.getInt("jump");
                    if (跳跃 > 0) {
                        name.append("#b跳跃 : #r").append(跳跃).append("#k\r\n");
                    }
                    int 可升级次数 = rs.getInt("upgradeslots");
                    if (可升级次数 > 0) {
                        name.append("#b可升级次数 : #r").append(可升级次数).append("#k\r\n");
                    }
                    int 已升级次数 = rs.getInt("level");
                    if (已升级次数 > 0) {
                        name.append("#b已升级次数 : #r").append(已升级次数).append("#k\r\n");
                    }
                    int 锤子次数 = rs.getInt("ViciousHammer");
                    if (锤子次数 > 0) {
                        name.append("#b锤子次数 : #r").append(锤子次数).append("#k\r\n");
                    }
                    String 名字 = rs.getString("owner");
                    if (名字 != null) {
                        name.append("#b星星潜能等级 : #r").append(名字).append("#k\r\n");
                    }
                }
            }
            rs.close();
            ps.close();
            
        } catch (SQLException ex) {
            System.err.println("显示物品列表详细、出错" + ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        name.append("\r\n");
        return name.toString();
    }

    public void 添加道具到拍卖行(int a1, int a2, int a3, int a4, String a5, String a6, int a7, int a8, int a9, String a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23, int a24, int a25, int a26, int a27, int a28) {
        MapleItemInformationProvider.getInstance();
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        if (ii.isQuestItem(a2)) {
            this.c.getPlayer().dropMessage(1, "任务物品，无法上架。");
            this.c.getSession().write(MaplePacketCreator.enableActions());
            return;
        }
        try (Connection con = BeePool.getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO auctionitems (characterid , price ,itemid ,inventorytype ,quantity ,owner ,GM_Log ,uniqueid ,flag ,expiredate ,sender ,upgradeslots ,level ,str ,dex ,_int ,luk ,hp ,mp ,watk ,matk ,wdef ,mdef ,acc ,avoid ,hands ,speed ,jump, world , ViciousHammer) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")) {
            ps.setInt(1, this.getPlayer().getId());
            ps.setInt(2, a1);
            ps.setInt(3, a2);
            ps.setInt(4, a3);
            ps.setInt(5, a4);
            ps.setString(6, a5);
            ps.setString(7, a6);
            ps.setInt(8, a7);
            ps.setByte(9, (byte) a8);
            ps.setLong(10, (long) a9);
            ps.setString(11, a10);
            ps.setInt(12, a11);
            ps.setInt(13, a12);
            ps.setInt(14, a13);
            ps.setInt(15, a14);
            ps.setInt(16, a15);
            ps.setInt(17, a16);
            ps.setInt(18, a17);
            ps.setInt(19, a18);
            ps.setInt(20, a19);
            ps.setInt(21, a20);
            ps.setInt(22, a21);
            ps.setInt(23, a22);
            ps.setInt(24, a23);
            ps.setInt(25, a24);
            ps.setInt(26, a25);
            ps.setInt(27, a26);
            ps.setInt(28, a27);
            ps.setInt(29, (int) this.getPlayer().getWorld());
            ps.setInt(30, a28);
            ps.executeUpdate();
        } catch (SQLException ex) {
            System.out.println("添加道具到拍卖行" + ex);
        }
    }

    public void 购买拍卖行装备(int a) {
        if (this.物品存在(a) > 0) {
            try (Connection con = BeePool.getConnection()) {
                try (PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE id = " + a + "");
                     ResultSet rs = ps.executeQuery()) {
                    if (rs.next()) {
                        if (rs.getInt("inventorytype") == 1) {
                            int 物品 = rs.getInt("itemid");
                            int 攻击力 = rs.getInt("watk");
                            int 魔法力 = rs.getInt("matk");
                            int 物理防御 = rs.getInt("wdef");
                            int 魔法防御 = rs.getInt("mdef");
                            int 力量 = rs.getInt("str");
                            int 敏捷 = rs.getInt("dex");
                            int 智力 = rs.getInt("_int");
                            int 运气 = rs.getInt("luk");
                            int 生命值 = rs.getInt("hp");
                            int 魔力值 = rs.getInt("mp");
                            int 命中 = rs.getInt("acc");
                            int 回避 = rs.getInt("avoid");
                            int 手技 = rs.getInt("hands");
                            int 移速 = rs.getInt("speed");
                            int 跳跃 = rs.getInt("jump");
                            int 可升级次数 = rs.getInt("upgradeslots");
                            int 已升级次数 = rs.getInt("level");
                            String 名字 = rs.getString("owner");
                            int 锤子 = rs.getInt("ViciousHammer");
                            this.给属性装备(物品, 可升级次数, 力量, 敏捷, 智力, 运气, 生命值, 魔力值, 攻击力, 魔法力, 物理防御, 魔法防御, 回避, 命中, 跳跃, 移速, 0L, 已升级次数, 手技, 名字, 锤子);
                        } else {
                            int 物品 = rs.getInt("itemid");
                            this.gainItem(物品, (short) rs.getInt("quantity"));
                        }
                    }
                    rs.close();
                    ps.close();
                }
                
            } catch (SQLException ex) {
                System.err.println("购买拍卖行装备、出错" + ex.getMessage());
            }
            finally {
                try {
                    if (con != null && !con.isClosed()) {
                        
                    }
                } catch (SQLException ignored) {
                }
            }
        }
    }

    public void 给属性装备(int id, int sj, int str, int dex, int Int, int luk, int hp, int mp, int watk, int matk, int wdef, int mdef, int hb, int mz, int ty, int yd, long 给予时间, int lv, int hands, String owner, int 锤子) {
        MapleItemInformationProvider.getInstance();
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        Equip item = (Equip) (Equip) ii.getEquipById(id);
        item.setUpgradeSlots((byte) (short) sj);
        if (lv > 0) {
            item.setLevel((byte) lv);
        }
        if (hands > 0) {
            item.setHands((short) hands);
        }
        if (str > 0) {
            item.setStr((short) str);
        }
        if (dex > 0) {
            item.setDex((short) dex);
        }
        if (luk > 0) {
            item.setLuk((short) luk);
        }
        if (Int > 0) {
            item.setInt((short) Int);
        }
        if (hp > 0) {
            item.setHp((short) hp);
        }
        if (mp > 0) {
            item.setMp((short) mp);
        }
        if (watk > 0) {
            item.setWatk((short) watk);
        }
        if (matk > 0) {
            item.setMatk((short) matk);
        }
        if (wdef > 0) {
            item.setWdef((short) wdef);
        }
        if (mdef > 0) {
            item.setMdef((short) mdef);
        }
        if (hb > 0) {
            item.setAvoid((short) hb);
        }
        if (mz > 0) {
            item.setAcc((short) mz);
        }
        if (ty > 0) {
            item.setJump((short) ty);
        }
        if (yd > 0) {
            item.setSpeed((short) yd);
        }
        if (给予时间 > 0L) {
            item.setExpiration(System.currentTimeMillis() + 给予时间 * 60L * 60L * 1000L);
        }
        if (owner != null) {
            item.setOwner(owner);
        }
        if (锤子 > 0) {
            item.setViciousHammer((byte) 锤子);
        }
        MapleInventoryManipulator.addbyItem(this.c, item.copy());
        this.c.sendPacket(MaplePacketCreator.getShowItemGain(id, (short) 1, true));
    }

    public void 删除购买的道具(int a) {
        PreparedStatement ps;
        ResultSet rs;
        try (Connection con = BeePool.getConnection()) {
            ps = con.prepareStatement("SELECT * FROM auctionitems WHERE id = " + a + "");
            rs = ps.executeQuery();
            while (rs.next()) {
                String sqlstr = " delete from auctionitems where id = '" + a + "' ";
                ps.executeUpdate(sqlstr);
            }
            ps.close();
        } catch (SQLException ex) {
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
    }

    public int 物品价格(int id) {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT price as DATA FROM auctionitems WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("物品价格、出错");
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex) {
            }
        }
        return data;
    }

    public int 物品存在(int id) {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    ++data;
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("物品存在、出错");
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex) {
            }
        }
        return data;
    }

    public int 物品卖家(int id) {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("SELECT characterid as DATA FROM auctionitems WHERE id = ?")) {
                ps.setInt(1, id);
                try (ResultSet rs = ps.executeQuery()) {
                    if (rs.next()) {
                        data = rs.getInt("DATA");
                    }
                    rs.close();
                }
                ps.close();
            }
            
        } catch (SQLException Ex) {
            System.err.println("物品卖家、出错");
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex) {
            }
        }
        return data;
    }

    public void 初始化拍卖储存(int a) {
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("INSERT INTO auctionpoint (characterid, point) values (?,?);");
            ps.setInt(1, a);
            ps.setInt(2, 0);
            ps.executeUpdate();
            ps.close();
            
        } catch (Exception ex) {
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
    }

    public void 新增拍卖存储金币(int a, int b) {
        if (this.判断拍卖存储金币(a) == 0) {
            this.初始化拍卖储存(a);
        }
        try (Connection con = BeePool.getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("UPDATE auctionpoint SET point = point + " + b + " WHERE characterid =" + a + "")) {
                ps.executeUpdate();
            }
        } catch (SQLException ex) {
            System.err.println(ex.getMessage());
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
    }

    public int 判断拍卖存储金币(int a) {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT point as DATA FROM auctionpoint WHERE characterid = ?");
            ps.setInt(1, a);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("判断拍卖存储金币、出错");
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex) {
            }
        }
        return data;
    }

    public void 清空拍卖存储金币() {
        try (Connection con = BeePool.getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("UPDATE auctionpoint SET point = 0 WHERE characterid =" + this.c.getPlayer().getId() + "")) {
                ps.executeUpdate();
                ps.close();
            }
            
        } catch (Exception ex) {
        }
    }

    public void 增加拍卖出售栏(int a) {
        try (Connection con = BeePool.getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("UPDATE auctionpoint SET selling = selling + " + a + " WHERE characterid =" + this.c.getPlayer().getId() + ";")) {
                ps.executeUpdate();
                ps.close();
            }
            
        } catch (Exception ex) {
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
    }

    public int 判断拍卖出售位数量() {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT selling  as DATA FROM auctionpoint WHERE characterid = ?;");
            ps.setInt(1, this.getPlayer().getId());
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data += rs.getInt("DATA");
                } else {
                    PreparedStatement psu = con.prepareStatement("insert into auctionpoint (characterid,point, selling) VALUES (?, ?, ?)");
                    psu.setInt(1, this.getPlayer().getId());
                    psu.setInt(2, 0);
                    psu.setInt(3, 10);
                    psu.executeUpdate();
                    psu.close();
                }
                rs.close();
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("判断拍卖出售位数量、出错");
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex) {
            }
        }
        return data;
    }

    public int 已经使用拍卖栏位() {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            try (PreparedStatement ps = con.prepareStatement("SELECT * FROM auctionitems WHERE characterid = ?")) {
                ps.setInt(1, this.getPlayer().getId());
                ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                    ++data;
                }
                rs.close();
            }
            
        } catch (SQLException ex) {
        }
        finally {
            try {
                if (con != null && !con.isClosed()) {
                    
                }
            } catch (SQLException ex2) {
            }
        }
        return data;
    }

    public String 取角色名字(int a) {
        return 角色名字(a);
    }

    public static String 角色名字(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM characters WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("角色名字、出错");
        }
        return data;
    }

    public void cleanItemBySlot(int slot, int type, int quantity) {
        MapleInventoryManipulator.removeFromSlot(this.c, MapleInventoryType.getByType((byte) type), (short) slot, (short) quantity, true);
    }

    public static String SN取出售(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? && channel = 1");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取库存(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 2");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public void 刷新地图() {
        boolean custMap = true;
        int mapid = this.c.getPlayer().getMapId();
        MapleMap map = custMap ? this.c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid) : this.c.getPlayer().getMap();
        if (this.c.getPlayer().getClient().getChannelServer().getMapFactory().destroyMap(mapid)) {
            MapleMap newMap = this.c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid);
            MaplePortal newPor = newMap.getPortal(0);
            LinkedHashSet<MapleCharacter> mcs = new LinkedHashSet(map.getCharacters());
            for (MapleCharacter m : mcs) {
                int x = 0;
                while (x < 5) {
                    try {
                        m.changeMap(newMap, newPor);
                    } catch (Throwable t) {
                        ++x;
                        continue;
                    }
                    break;
                }
            }
        }
    }

    public void 刷新地图(int a) {
        boolean custMap = true;
        int mapid = a;
        MapleMap map = custMap ? this.c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid) : this.c.getPlayer().getMap();
        if (this.c.getPlayer().getClient().getChannelServer().getMapFactory().destroyMap(mapid)) {
            MapleMap newMap = this.c.getPlayer().getClient().getChannelServer().getMapFactory().getMap(mapid);
            MaplePortal newPor = newMap.getPortal(0);
            LinkedHashSet<MapleCharacter> mcs = new LinkedHashSet(map.getCharacters());
            for (MapleCharacter m : mcs) {
                int x = 0;
                while (x < 5) {
                    try {
                        m.changeMap(newMap, newPor);
                    } catch (Throwable t) {
                        ++x;
                        continue;
                    }
                    break;
                }
            }
        }
    }

    public static String SN取折扣(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 3");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
            
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static String SN取限购(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 4");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public int 物品叠加数量(int id) {
        MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
        return ii.getSlotMax(this.c, id);
    }

    public static String SN取类型(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT Point as DATA FROM character7 WHERE Name = ? &&  channel = 5");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public List<Integer> getMobInMap(int mobid) {
        List<Integer> list = new ArrayList<>();
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("select * from mobinmap where mobid = ?");
            ps.setInt(1, mobid);
            try (ResultSet rs = ps.executeQuery()) {
                while (rs.next()) {
                    list.add(rs.getInt("mapid"));
                }
                rs.close();
            }
            ps.close();
            
            return list;
        } catch (Exception Ex) {
            FileoutputUtil.outError("logs/资料库异常.txt", (Throwable) Ex);
            return null;
        }
    }

    public static String 角色ID取名字(int id) {
        String data = "";
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT name as DATA FROM characters WHERE id = ?");
            ps.setInt(1, id);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getString("DATA");
                }
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        if (data == null) {
            data = "匿名人士";
        }
        return data;
    }

    public static int getMRJF(int id) {
        int jf = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("select * from paymoney1 where characterid =?");
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                jf = rs.getInt("mrjf");
            } else {
                PreparedStatement psu = con.prepareStatement("insert into paymoney1 (characterid,mrjf) VALUES (?,?)");
                psu.setInt(1, id);
                psu.setInt(2, 0);
                psu.executeUpdate();
                psu.close();
            }
            ps.close();
            rs.close();
        } catch (SQLException ex) {
            System.err.println("每日积分读取发生错误: " + ex);
        }
        return jf;
    }

    public static int 角色名字取Id(String name) {
        int data = 0;
        try (Connection con = BeePool.getConnection()) {
            PreparedStatement ps = con.prepareStatement("SELECT id as DATA FROM characters WHERE name = ?");
            ps.setString(1, name);
            try (ResultSet rs = ps.executeQuery()) {
                if (rs.next()) {
                    data = rs.getInt("DATA");
                }
                rs.close();
            }
            ps.close();
        } catch (SQLException Ex) {
            System.err.println("获取角色ID取名字出错 - 数据库查询失败：" + Ex);
        }
        return data;
    }

    public int getmoneyb() {
        return this.c.getPlayer().getLJJF(this.c.getPlayer().getId());
    }

    public void setmoneyb(int slot) {
        this.c.getPlayer().setLJJF(this.c.getPlayer().getId(), slot);
    }

    public String ms() {
        return Game.服务端名字;
    }

    public int 召唤扎昆() {
        int i = 0;
        this.c.getPlayer().getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(8800000), this.c.getPlayer().getPosition());
        for (i = 8800003; i <= 8800010; ++i) {
            this.c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(i), this.c.getPlayer().getPosition());
        }
        return 1;
    }

    public int 召唤黑龙() {
        this.c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.musicChange("Bgm14/HonTale"));
        this.c.getPlayer().getMap().spawnMonsterOnGroundBelow(MapleLifeFactory.getMonster(8810026), this.c.getPlayer().getPosition());
        return 1;
    }

    public int 召唤闹钟() {
        MapleMonster mob0 = MapleLifeFactory.getMonster(8500001);
        this.c.getPlayer().getMap().spawnMonsterOnGroundBelow(mob0, this.c.getPlayer().getPosition());
        return 1;
    }

    public void 全服漂浮喇叭(String msg, int itemId) {
        int ret = 0;
        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
            for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {
                mch.startMapEffect(msg, itemId);
                ++ret;
            }
        }
    }

    public int 获取玩家状态信息(String type) {
        switch (type) {
            case PlayerStatusTypeConstants.PLAYER_LVL -> {
                return this.getClient().getPlayer().getLevel();
            }
            case PlayerStatusTypeConstants.PLAYER_STR -> {
                return this.getClient().getPlayer().getStat().getStr();
            }
            case PlayerStatusTypeConstants.PLAYER_DEX -> {
                return this.getClient().getPlayer().getStat().getDex();
            }
            case PlayerStatusTypeConstants.PLAYER_INT -> {
                return this.getClient().getPlayer().getStat().getInt();
            }
            case PlayerStatusTypeConstants.PLAYER_LUK -> {
                return this.getClient().getPlayer().getStat().getLuk();
            }
            case PlayerStatusTypeConstants.PLAYER_HP -> {
                return this.getClient().getPlayer().getStat().getHp();
            }
            case PlayerStatusTypeConstants.PLAYER_MP -> {
                return this.getClient().getPlayer().getStat().getMp();
            }
            case PlayerStatusTypeConstants.PLAYER_MAX_HP -> {
                return this.getClient().getPlayer().getStat().getMaxHp();
            }
            case PlayerStatusTypeConstants.PLAYER_MAX_MP -> {
                return this.getClient().getPlayer().getStat().getMaxMp();
            }
            case PlayerStatusTypeConstants.PLAYER_RAP -> {
                return this.getClient().getPlayer().getRemainingAp();
            }
            case PlayerStatusTypeConstants.PLAYER_RSP -> {
                return this.getClient().getPlayer().getRemainingSp();
            }
            case PlayerStatusTypeConstants.PLAYER_GID -> {
                return this.getClient().getPlayer().getGuildId();
            }
            case PlayerStatusTypeConstants.PLAYER_G_RANK -> {
                return this.getClient().getPlayer().getGuildRank();
            }
            case PlayerStatusTypeConstants.PLAYER_A_RANK -> {
                return this.getClient().getPlayer().getAllianceRank();
            }
            case PlayerStatusTypeConstants.PLAYER_GM -> {
                return this.getClient().getPlayer().isGM() ? 1 : 0;
            }
            case PlayerStatusTypeConstants.PLAYER_ADMIN -> {
                return this.getClient().getPlayer().hasGmLevel(5) ? 1 : 0;
            }
            case PlayerStatusTypeConstants.PLAYER_GENDER -> {
                return this.getClient().getPlayer().getGender();
            }
            case PlayerStatusTypeConstants.PLAYER_FACE -> {
                return this.getClient().getPlayer().getFace();
            }
            case PlayerStatusTypeConstants.PLAYER_HAIR -> {
                return this.getClient().getPlayer().getHair();
            }
            default -> {
                return -1;
            }
        }
    }

    public boolean isEligibleName(String t) {
        return MapleCharacterUtil.canCreateChar(t, this.getPlayer().isGM()) && (!LoginInformationProvider.getInstance().isForbiddenName(t) || this.getPlayer().isGM());
    }

    public void displayBossLogRanks(String bossName) {
        this.c.sendPacket(MaplePacketCreator.showBossLogRanks(this.npc, MapleGuildRanking.getInstance().getBossLogRank(bossName, (int) this.c.getPlayer().getWorld())));
    }

    public boolean hasgy() {
        return World.hasMerchant(this.c.getPlayer().getAccountID());
    }

    public int getFZ4(String log1) {
        return this.c.getPlayer().getFZ4(log1);
    }

    public void setFZ4(String log1, int a) {
        this.c.getPlayer().setFZ4(log1, a);
    }


    /**
     * 获取角色所有仓库道具
     *
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> getMaterialAll() throws Exception {
        return characterMaterialMapper.queryByUserList(c.getPlayer().getId());
    }

    /**
     * 获取角色单个仓库道具
     *
     * @param itemId
     * @return
     * @throws Exception
     */
    public Map<String, Object> getMaterialOne(int itemId) throws Exception {
        return characterMaterialMapper.queryByUserOne(c.getPlayer().getId(), itemId);
    }

    /**
     * 修改材料仓库道具数量
     *
     * @param number
     * @param itemId
     * @throws Exception
     */
    public void updateMaterialCount(int number, int itemId) throws Exception {
        characterMaterialMapper.updateCount(number, itemId, c.getPlayer().getId());
    }

    /**
     * @Author cc
     * @Description 批量保存材料
     */
    public void saveMaterialBatch(List<Map<String, Integer>> items) throws Exception {
        characterMaterialMapper.saveBatch(items);
    }


    /**
     * @Author cc
     * @Description 批量删除仓库材料
     */
    public void deleteMaterialBatch() throws Exception {
        characterMaterialMapper.deleteBatch(c.getPlayer().getId());
    }

    /**
     * @Author cc
     * @Description 检查仓库是否存在物品
     */
    public Boolean isMaterialExist() throws Exception {
        return ObjectUtil.isNotEmpty(characterMaterialMapper.queryByUserList(c.getPlayer().getId()));
    }

}
